Skip to content

Commit 1233ddd

Browse files
committed
Convert macros to inline functions in Zend SmartStr
1 parent 8dcb034 commit 1233ddd

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

Zend/zend_smart_str.h

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +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_extend(dest, len) \
29-
smart_str_extend_ex((dest), (len), 0)
30-
#define smart_str_appendc(dest, c) \
31-
smart_str_appendc_ex((dest), (c), 0)
32-
#define smart_str_appendl(dest, src, len) \
33-
smart_str_appendl_ex((dest), (src), (len), 0)
34-
#define smart_str_append(dest, src) \
35-
smart_str_append_ex((dest), (src), 0)
36-
#define smart_str_append_smart_str(dest, src) \
37-
smart_str_append_smart_str_ex((dest), (src), 0)
38-
#define smart_str_sets(dest, src) \
39-
smart_str_setl((dest), (src), strlen(src));
40-
#define smart_str_append_long(dest, val) \
41-
smart_str_append_long_ex((dest), (val), 0)
42-
#define smart_str_append_unsigned(dest, val) \
43-
smart_str_append_unsigned_ex((dest), (val), 0)
44-
#define smart_str_free(dest) \
45-
smart_str_free_ex((dest), 0)
46-
4724
BEGIN_EXTERN_C()
4825

4926
ZEND_API void ZEND_FASTCALL smart_str_erealloc(smart_str *str, size_t len);
@@ -83,6 +60,11 @@ static zend_always_inline char* smart_str_extend_ex(smart_str *dest, size_t len,
8360
return ret;
8461
}
8562

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+
8668
static zend_always_inline void smart_str_free_ex(smart_str *str, bool persistent) {
8769
if (str->s) {
8870
zend_string_release_ex(str->s, persistent);
@@ -91,6 +73,11 @@ static zend_always_inline void smart_str_free_ex(smart_str *str, bool persistent
9173
str->a = 0;
9274
}
9375

76+
static inline void smart_str_free(smart_str *str)
77+
{
78+
smart_str_free_ex(str, false);
79+
}
80+
9481
static zend_always_inline void smart_str_0(smart_str *str) {
9582
if (str->s) {
9683
ZSTR_VAL(str->s)[ZSTR_LEN(str->s)] = '\0';
@@ -141,15 +128,54 @@ static zend_always_inline void smart_str_append_long_ex(smart_str *dest, zend_lo
141128
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
142129
}
143130

131+
static inline void smart_str_append_long(smart_str *dest, zend_long num)
132+
{
133+
smart_str_append_long_ex(dest, num, false);
134+
}
135+
144136
static zend_always_inline void smart_str_append_unsigned_ex(smart_str *dest, zend_ulong num, bool persistent) {
145137
char buf[32];
146138
char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
147139
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
148140
}
149141

142+
static inline void smart_str_append_unsigned(smart_str *dest, zend_ulong num)
143+
{
144+
smart_str_append_unsigned_ex(dest, num, false);
145+
}
146+
147+
static inline void smart_str_appendl(smart_str *dest, const char *src, size_t length)
148+
{
149+
smart_str_appendl_ex(dest, src, length, false);
150+
}
151+
static inline void smart_str_appends_ex(smart_str *dest, const char *src, bool persistent)
152+
{
153+
smart_str_appendl_ex(dest, src, strlen(src), persistent);
154+
}
155+
static inline void smart_str_appends(smart_str *dest, const char *src)
156+
{
157+
smart_str_appendl_ex(dest, src, strlen(src), false);
158+
}
159+
static inline void smart_str_append(smart_str *dest, const zend_string *src)
160+
{
161+
smart_str_append_ex(dest, src, false);
162+
}
163+
static inline void smart_str_appendc(smart_str *dest, char ch)
164+
{
165+
smart_str_appendc_ex(dest, ch, false);
166+
}
167+
static inline void smart_str_append_smart_str(smart_str *dest, const smart_str *src)
168+
{
169+
smart_str_append_smart_str_ex(dest, src, false);
170+
}
171+
150172
static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
151173
smart_str_free(dest);
152174
smart_str_appendl(dest, src, len);
153175
}
154176

177+
static inline void smart_str_sets(smart_str *dest, const char *src)
178+
{
179+
smart_str_setl(dest, src, strlen(src));
180+
}
155181
#endif

0 commit comments

Comments
 (0)