Skip to content

Commit 6298ea2

Browse files
committed
Convert macros to inline functions in Zend SmartStr
1 parent fc6b3c1 commit 6298ea2

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

Zend/zend_smart_str.h

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,6 @@
2121
#include "zend_globals.h"
2222
#include "zend_smart_str_public.h"
2323

24-
#define smart_str_appends_ex(dest, src, what) \
25-
smart_str_appendl_ex((dest), (src), strlen(src), (what))
26-
#define smart_str_appends(dest, src) \
27-
smart_str_appendl((dest), (src), strlen(src))
28-
#define smart_str_extract(dest) \
29-
smart_str_extract_ex((dest), 0)
30-
#define smart_str_trim_to_size(dest) \
31-
smart_str_trim_to_size_ex((dest), 0)
32-
#define smart_str_extend(dest, len) \
33-
smart_str_extend_ex((dest), (len), 0)
34-
#define smart_str_appendc(dest, c) \
35-
smart_str_appendc_ex((dest), (c), 0)
36-
#define smart_str_appendl(dest, src, len) \
37-
smart_str_appendl_ex((dest), (src), (len), 0)
38-
#define smart_str_append(dest, src) \
39-
smart_str_append_ex((dest), (src), 0)
40-
#define smart_str_append_smart_str(dest, src) \
41-
smart_str_append_smart_str_ex((dest), (src), 0)
42-
#define smart_str_sets(dest, src) \
43-
smart_str_setl((dest), (src), strlen(src));
44-
#define smart_str_append_long(dest, val) \
45-
smart_str_append_long_ex((dest), (val), 0)
46-
#define smart_str_append_unsigned(dest, val) \
47-
smart_str_append_unsigned_ex((dest), (val), 0)
48-
#define smart_str_free(dest) \
49-
smart_str_free_ex((dest), 0)
50-
5124
BEGIN_EXTERN_C()
5225

5326
ZEND_API void ZEND_FASTCALL smart_str_erealloc(smart_str *str, size_t len);
@@ -87,6 +60,11 @@ static zend_always_inline char* smart_str_extend_ex(smart_str *dest, size_t len,
8760
return ret;
8861
}
8962

63+
static inline char* smart_str_extend(smart_str *dest, size_t length)
64+
{
65+
return smart_str_extend_ex(dest, length, false);
66+
}
67+
9068
static zend_always_inline void smart_str_free_ex(smart_str *str, bool persistent) {
9169
if (str->s) {
9270
zend_string_release_ex(str->s, persistent);
@@ -95,6 +73,11 @@ static zend_always_inline void smart_str_free_ex(smart_str *str, bool persistent
9573
str->a = 0;
9674
}
9775

76+
static inline void smart_str_free(smart_str *str)
77+
{
78+
smart_str_free_ex(str, false);
79+
}
80+
9881
static zend_always_inline void smart_str_0(smart_str *str) {
9982
if (str->s) {
10083
ZSTR_VAL(str->s)[ZSTR_LEN(str->s)] = '\0';
@@ -113,6 +96,11 @@ static zend_always_inline void smart_str_trim_to_size_ex(smart_str *str, bool pe
11396
}
11497
}
11598

99+
static inline void smart_str_trim_to_size(smart_str *dest)
100+
{
101+
smart_str_trim_to_size_ex(dest, false);
102+
}
103+
116104
static zend_always_inline zend_string *smart_str_extract_ex(smart_str *str, bool persistent) {
117105
if (str->s) {
118106
zend_string *res;
@@ -126,6 +114,11 @@ static zend_always_inline zend_string *smart_str_extract_ex(smart_str *str, bool
126114
}
127115
}
128116

117+
static inline zend_string smart_str_extract(smart_str *dest)
118+
{
119+
return smart_str_extract_ex(dest, false);
120+
}
121+
129122
static zend_always_inline void smart_str_appendc_ex(smart_str *dest, char ch, bool persistent) {
130123
size_t new_len = smart_str_alloc(dest, 1, persistent);
131124
ZSTR_VAL(dest->s)[new_len - 1] = ch;
@@ -154,15 +147,54 @@ static zend_always_inline void smart_str_append_long_ex(smart_str *dest, zend_lo
154147
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
155148
}
156149

150+
static inline void smart_str_append_long(smart_str *dest, zend_long num)
151+
{
152+
smart_str_append_long_ex(dest, num, false);
153+
}
154+
157155
static zend_always_inline void smart_str_append_unsigned_ex(smart_str *dest, zend_ulong num, bool persistent) {
158156
char buf[32];
159157
char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
160158
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
161159
}
162160

161+
static inline void smart_str_append_unsigned(smart_str *dest, zend_ulong num)
162+
{
163+
smart_str_append_unsigned_ex(dest, num, false);
164+
}
165+
166+
static inline void smart_str_appendl(smart_str *dest, const char *src, size_t length)
167+
{
168+
smart_str_appendl_ex(dest, src, length, false);
169+
}
170+
static inline void smart_str_appends_ex(smart_str *dest, const char *src, bool persistent)
171+
{
172+
smart_str_appendl_ex(dest, src, strlen(src), persistent);
173+
}
174+
static inline void smart_str_appends(smart_str *dest, const char *src)
175+
{
176+
smart_str_appendl_ex(dest, src, strlen(src), false);
177+
}
178+
static inline void smart_str_append(smart_str *dest, const zend_string *src)
179+
{
180+
smart_str_append_ex(dest, src, false);
181+
}
182+
static inline void smart_str_appendc(smart_str *dest, char ch)
183+
{
184+
smart_str_appendc_ex(dest, ch, false);
185+
}
186+
static inline void smart_str_append_smart_str(smart_str *dest, const smart_str *src)
187+
{
188+
smart_str_append_smart_str_ex(dest, src, false);
189+
}
190+
163191
static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
164192
smart_str_free(dest);
165193
smart_str_appendl(dest, src, len);
166194
}
167195

196+
static inline void smart_str_sets(smart_str *dest, const char *src)
197+
{
198+
smart_str_setl(dest, src, strlen(src));
199+
}
168200
#endif

0 commit comments

Comments
 (0)