summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-09-19 22:16:01 +0200
committerNikita Popov <nikic@php.net>2014-09-19 23:39:07 +0200
commit37aaccad7d8b9428c69f8c03806e1635575f216b (patch)
tree4c7ed96fb8f9082224df6c3420a3f1b589d4cc57 /ext
parent070667de8db929454aee13c5185b165554c00c55 (diff)
downloadphp-git-37aaccad7d8b9428c69f8c03806e1635575f216b.tar.gz
Use inline functions for most of smart_str
smart_str_free_ex no longer exists, always use smart_str_free instead. smart_str_alloc no longer requires a newlen variable to be in scope, instead it returns the new length.
Diffstat (limited to 'ext')
-rw-r--r--ext/iconv/iconv.c10
-rw-r--r--ext/json/json.c2
-rw-r--r--ext/oci8/oci8.c12
-rw-r--r--ext/sockets/conversions.c2
-rw-r--r--ext/standard/php_smart_str.h125
-rw-r--r--ext/standard/var.c2
6 files changed, 65 insertions, 88 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index ace1ce2b67..7ca97f9418 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -462,10 +462,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l,
if (in_p != NULL) {
while (in_left > 0) {
out_left = buf_growth - out_left;
- {
- size_t newlen;
- smart_str_alloc((d), out_left, 0);
- }
+ smart_str_alloc(d, out_left, 0);
out_p = (d)->s->val + (d)->s->len;
@@ -499,10 +496,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l,
} else {
for (;;) {
out_left = buf_growth - out_left;
- {
- size_t newlen;
- smart_str_alloc((d), out_left, 0);
- }
+ smart_str_alloc(d, out_left, 0);
out_p = (d)->s->val + (d)->s->len;
diff --git a/ext/json/json.c b/ext/json/json.c
index 4b4522ed30..485d14d11b 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -384,7 +384,7 @@ static void json_escape_string(smart_str *buf, char *s, size_t len, int options
{
int status;
unsigned int us, next_us = 0;
- size_t pos, checkpoint, newlen;
+ size_t pos, checkpoint;
if (len == 0) {
smart_str_appendl(buf, "\"\"", 2);
diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c
index 0bcb366803..c941c8eaf2 100644
--- a/ext/oci8/oci8.c
+++ b/ext/oci8/oci8.c
@@ -1971,7 +1971,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
*/
if (connection && connection->is_persistent && connection->is_stub) {
if (php_oci_create_session(connection, NULL, dbname, dbname_len, username, username_len, password, password_len, new_password, new_password_len, session_mode TSRMLS_CC)) {
- smart_str_free_ex(&hashed_details, 0);
+ smart_str_free(&hashed_details);
zend_hash_del(&EG(persistent_list), connection->hash_key);
return NULL;
@@ -2022,14 +2022,14 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
++GC_REFCOUNT(connection->id);
}
}
- smart_str_free_ex(&hashed_details, 0);
+ smart_str_free(&hashed_details);
return connection;
}
}
/* server died */
} else {
/* we do not ping non-persistent connections */
- smart_str_free_ex(&hashed_details, 0);
+ smart_str_free(&hashed_details);
++GC_REFCOUNT(connection->id);
return connection;
}
@@ -2130,7 +2130,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
if ((session_pool = php_oci_get_spool(username, username_len, password, password_len, dbname, dbname_len, charsetid ? charsetid:charsetid_nls_lang TSRMLS_CC))==NULL)
{
php_oci_connection_close(connection TSRMLS_CC);
- smart_str_free_ex(&hashed_details, 0);
+ smart_str_free(&hashed_details);
return NULL;
}
}
@@ -2141,7 +2141,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
/* Mark password as unchanged by PHP during the duration of the database session */
connection->passwd_changed = 0;
- smart_str_free_ex(&hashed_details, 0);
+ smart_str_free(&hashed_details);
if (charsetid) {
connection->charset = charsetid;
@@ -3031,7 +3031,7 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
}
exit_get_spool:
- smart_str_free_ex(&spool_hashed_details, 0);
+ smart_str_free(&spool_hashed_details);
if (iserror && session_pool) {
php_oci_spool_close(session_pool TSRMLS_CC);
session_pool = NULL;
diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c
index d9221e52f5..f31208cf4d 100644
--- a/ext/sockets/conversions.c
+++ b/ext/sockets/conversions.c
@@ -175,7 +175,7 @@ static void do_from_to_zval_err(struct err_s *err,
err->should_free = 1;
efree(user_msg);
- smart_str_free_ex(&path, 0);
+ smart_str_free(&path);
}
ZEND_ATTRIBUTE_FORMAT(printf, 2 ,3)
static void do_from_zval_err(ser_context *ctx, const char *fmt, ...)
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index 57590f561d..25d6fe2db4 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -26,12 +26,6 @@
#include <stdlib.h>
#include <zend.h>
-#define smart_str_0(x) do { \
- if ((x)->s) { \
- (x)->s->val[(x)->s->len] = '\0'; \
- } \
-} while (0)
-
#ifndef SMART_STR_PREALLOC
#define SMART_STR_PREALLOC 128
#endif
@@ -40,41 +34,20 @@
#define SMART_STR_START_SIZE 78
#endif
-#define smart_str_alloc4(d, n, what, newlen) do { \
- if (!(d)->s) { \
- newlen = (n); \
- (d)->a = newlen < SMART_STR_START_SIZE \
- ? SMART_STR_START_SIZE \
- : newlen + SMART_STR_PREALLOC; \
- (d)->s = zend_string_alloc((d)->a, (what)); \
- (d)->s->len = 0; \
- } else { \
- newlen = (d)->s->len + (n); \
- if (newlen >= (d)->a) { \
- (d)->a = newlen + SMART_STR_PREALLOC; \
- (d)->s = perealloc((d)->s, _STR_HEADER_SIZE + (d)->a + 1, (what)); \
- } \
- } \
-} while (0)
-
-#define smart_str_alloc(d, n, what) \
- smart_str_alloc4((d), (n), (what), newlen)
-
/* wrapper */
#define smart_str_appends_ex(dest, src, what) \
smart_str_appendl_ex((dest), (src), strlen(src), (what))
#define smart_str_appends(dest, src) \
smart_str_appendl((dest), (src), strlen(src))
-
#define smart_str_appendc(dest, c) \
smart_str_appendc_ex((dest), (c), 0)
-#define smart_str_free(s) \
- smart_str_free_ex((s), 0)
#define smart_str_appendl(dest, src, len) \
smart_str_appendl_ex((dest), (src), (len), 0)
#define smart_str_append(dest, src) \
smart_str_append_ex((dest), (src), 0)
+#define smart_str_sets(dest, src) \
+ smart_str_setl((dest), (src), strlen(src));
#define smart_str_append_long(dest, val) \
smart_str_append_long_ex((dest), (val), 0)
#define smart_str_append_off_t(dest, val) \
@@ -82,37 +55,61 @@
#define smart_str_append_unsigned(dest, val) \
smart_str_append_unsigned_ex((dest), (val), 0)
-#define smart_str_appendc_ex(dest, ch, what) do { \
- register size_t __nl; \
- smart_str_alloc4((dest), 1, (what), __nl); \
- (dest)->s->len = __nl; \
- ((unsigned char *) (dest)->s->val)[(dest)->s->len - 1] = (ch); \
-} while (0)
+static zend_always_inline size_t smart_str_alloc(smart_str *str, size_t len, zend_bool persistent) {
+ size_t newlen;
+ if (!str->s) {
+ newlen = len;
+ str->a = newlen < SMART_STR_START_SIZE
+ ? SMART_STR_START_SIZE
+ : newlen + SMART_STR_PREALLOC;
+ str->s = zend_string_alloc(str->a, persistent);
+ str->s->len = 0;
+ } else {
+ newlen = str->s->len + len;
+ if (newlen >= str->a) {
+ str->a = newlen + SMART_STR_PREALLOC;
+ str->s = perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent);
+ }
+ }
+ return newlen;
+}
-#define smart_str_free_ex(buf, what) do { \
- smart_str *__s = (smart_str *) (buf); \
- if (__s->s) { \
- zend_string_release(__s->s); \
- __s->s = NULL; \
- } \
- __s->a = 0; \
-} while (0)
+static zend_always_inline void smart_str_free(smart_str *str) {
+ if (str->s) {
+ zend_string_release(str->s);
+ str->s = NULL;
+ }
+ str->a = 0;
+}
-#define smart_str_appendl_ex(dest, src, nlen, what) do { \
- register size_t __nl; \
- smart_str *__dest = (smart_str *) (dest); \
- \
- smart_str_alloc4(__dest, (nlen), (what), __nl); \
- memcpy(__dest->s->val + __dest->s->len, (src), (nlen)); \
- __dest->s->len = __nl; \
-} while (0)
+static zend_always_inline void smart_str_0(smart_str *str) {
+ if (str->s) {
+ str->s->val[str->s->len] = '\0';
+ }
+}
-/*
- * these could be replaced using a braced-group inside an expression
- * for GCC compatible compilers, e.g.
- *
- * #define f(..) ({char *r;..;__r;})
- */
+static zend_always_inline void smart_str_appendc_ex(smart_str *dest, char ch, zend_bool persistent) {
+ size_t new_len = smart_str_alloc(dest, 1, persistent);
+ dest->s->val[new_len - 1] = ch;
+ dest->s->len = new_len;
+}
+
+static zend_always_inline void smart_str_appendl_ex(smart_str *dest, const char *str, size_t len, zend_bool persistent) {
+ size_t new_len = smart_str_alloc(dest, len, persistent);
+ memcpy(dest->s->val + dest->s->len, str, len);
+ dest->s->len = new_len;
+}
+
+static zend_always_inline void smart_str_append_ex(smart_str *dest, const smart_str *src, zend_bool persistent) {
+ if (src->s && src->s->len) {
+ smart_str_appendl_ex(dest, src->s->val, src->s->len, persistent);
+ }
+}
+
+static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
+ smart_str_free(dest);
+ smart_str_appendl(dest, src, len);
+}
static inline char *smart_str_print_long(char *buf, zend_long num) {
char *r;
@@ -142,18 +139,4 @@ static inline char *smart_str_print_unsigned(char *buf, zend_long num) {
#define smart_str_append_off_t_ex(dest, num, type) \
smart_str_append_generic_ex((dest), (num), (type), zend_off_t, _signed)
-#define smart_str_append_ex(dest, src, what) do { \
- if ((src)->s && (src)->s->len) { \
- smart_str_appendl_ex((dest), (src)->s->val, (src)->s->len, (what)); \
- } \
-} while(0)
-
-#define smart_str_setl(dest, src, nlen) do { \
- smart_str_free((dest)); \
- smart_str_appendl_ex((dest), (src), (nlen), 0); \
-} while (0)
-
-#define smart_str_sets(dest, src) \
- smart_str_setl((dest), (src), strlen(src));
-
#endif
diff --git a/ext/standard/var.c b/ext/standard/var.c
index c99226a110..d320124e5f 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -865,7 +865,7 @@ again:
smart_str_append_long(buf, (int)serialized_length);
smart_str_appendl(buf, ":{", 2);
- smart_str_appendl(buf, serialized_data, serialized_length);
+ smart_str_appendl(buf, (char *) serialized_data, serialized_length);
smart_str_appendc(buf, '}');
} else {
smart_str_appendl(buf, "N;", 2);