]> granicus.if.org Git - php/commitdiff
Optimize zend_string_realloc() add more specialized versions zend_string_extend(...
authorDmitry Stogov <dmitry@zend.com>
Thu, 19 Mar 2015 23:02:42 +0000 (02:02 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 19 Mar 2015 23:02:42 +0000 (02:02 +0300)
28 files changed:
Zend/zend_compile.c
Zend/zend_execute.c
Zend/zend_ini_parser.y
Zend/zend_language_scanner.c
Zend/zend_language_scanner.l
Zend/zend_operators.c
Zend/zend_string.h
ext/date/php_date.c
ext/iconv/iconv.c
ext/mysqli/mysqli_api.c
ext/oci8/oci8_statement.c
ext/opcache/Optimizer/block_pass.c
ext/pcre/php_pcre.c
ext/pgsql/pgsql.c
ext/reflection/php_reflection.c
ext/sockets/sockets.c
ext/spl/php_spl.c
ext/standard/exec.c
ext/standard/formatted_print.c
ext/standard/metaphone.c
ext/standard/quot_print.c
ext/standard/string.c
ext/standard/url.c
ext/standard/uuencode.c
ext/wddx/wddx.c
ext/xml/xml.c
ext/zlib/zlib.c
main/streams/streams.c

index 962bb14b42a0651c258b1fa2ef043b8592f76139..b7c25eea8d321e64a1ca71d2132fd443cc7d8b61 100644 (file)
@@ -1500,7 +1500,7 @@ zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
        size_t left_len = left->len;
        size_t len = left_len + right->len + 1; /* left\right */
 
-       result = zend_string_realloc(left, len, 0);
+       result = zend_string_extend(left, len, 0);
        result->val[left_len] = '\\';
        memcpy(&result->val[left_len + 1], right->val, right->len);
        result->val[len] = '\0';
@@ -5225,7 +5225,7 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
                        zend_dirname(dirname->val, dirname->len);
 
                        if (strcmp(dirname->val, ".") == 0) {
-                               dirname = zend_string_realloc(dirname, MAXPATHLEN, 0);
+                               dirname = zend_string_extend(dirname, MAXPATHLEN, 0);
 #if HAVE_GETCWD
                                VCWD_GETCWD(dirname->val, MAXPATHLEN);
 #elif HAVE_GETWD
index 1692baa9991ba4a8dbc34e121a9c593b70e1945a..caaeb6a5fd1b3462600ea0b794e1e8dbe505c693 100644 (file)
@@ -1136,7 +1136,7 @@ static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *valu
        old_str = Z_STR_P(str);
        if ((size_t)offset >= Z_STRLEN_P(str)) {
                zend_long old_len = Z_STRLEN_P(str);
-               Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0);
+               Z_STR_P(str) = zend_string_extend(Z_STR_P(str), offset + 1, 0);
                Z_TYPE_INFO_P(str) = IS_STRING_EX;
                memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
                Z_STRVAL_P(str)[offset+1] = 0;
index f9c8581ab9668500e246871f2ca156ca99e7b384..572d70f2480c39d593c4657238397612dcb79d44 100644 (file)
@@ -105,7 +105,7 @@ static void zend_ini_add_string(zval *result, zval *op1, zval *op2)
        int op1_len = (int)Z_STRLEN_P(op1);
        int length = op1_len + (int)Z_STRLEN_P(op2);
 
-       ZVAL_NEW_STR(result, zend_string_realloc(Z_STR_P(op1), length, 1));
+       ZVAL_NEW_STR(result, zend_string_extend(Z_STR_P(op1), length, 1));
        memcpy(Z_STRVAL_P(result)+op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
        Z_STRVAL_P(result)[length] = 0;
 }
index 3ddf7e86c38f44220549426a810c0052feaeb6d9..edde9ca870994a5554a312553a028d7473760240 100644 (file)
@@ -657,7 +657,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
 
        /* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
        old_len = Z_STRLEN_P(str);
-       Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
+       Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
        Z_TYPE_INFO_P(str) = IS_STRING_EX;
        memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);
 
index 5cf83f506ba4d186a13821f6343e0794ca82c086..941a6cbceaebd9c17741baf4b967615796b8bd2d 100644 (file)
@@ -655,7 +655,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
 
        /* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
        old_len = Z_STRLEN_P(str);
-       Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
+       Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
        Z_TYPE_INFO_P(str) = IS_STRING_EX;
        memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);
 
index d8e92a97ad1c088f855c6c3a3e485162aece1701..8a58f3791ed7bc057366d31a16a9a75e551d9c41 100644 (file)
@@ -1501,7 +1501,7 @@ ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *o
 ZEND_API int ZEND_FASTCALL add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
 {
        size_t length = Z_STRLEN_P(op1) + 1;
-       zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
+       zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
 
        buf->val[length - 1] = (char) Z_LVAL_P(op2);
        buf->val[length] = 0;
@@ -1515,7 +1515,7 @@ ZEND_API int ZEND_FASTCALL add_string_to_string(zval *result, const zval *op1, c
 {
        size_t op1_len = Z_STRLEN_P(op1);
        size_t length = op1_len + Z_STRLEN_P(op2);
-       zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
+       zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
 
        memcpy(buf->val + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
        buf->val[length] = 0;
@@ -1577,7 +1577,7 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
 
                if (result == op1 && Z_REFCOUNTED_P(result)) {
                        /* special case, perform operations on result */
-                       result_str = zend_string_realloc(Z_STR_P(result), result_len, 0);
+                       result_str = zend_string_extend(Z_STR_P(result), result_len, 0);
                } else {
                        result_str = zend_string_alloc(result_len, 0);
                        memcpy(result_str->val, Z_STRVAL_P(op1), op1_len);
index b7605efc09d6573640ee1e49271d9200fc857c85..29985b73356e1760052b2a237ad4b0ae858f1aa5 100644 (file)
@@ -158,18 +158,58 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
 {
        zend_string *ret;
 
-       if (IS_INTERNED(s)) {
-               ret = zend_string_alloc(len, persistent);
-               memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
-       } else if (EXPECTED(GC_REFCOUNT(s) == 1)) {
-               ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
-               ret->len = len;
-               zend_string_forget_hash_val(ret);
-       } else {
-               ret = zend_string_alloc(len, persistent);
-               memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
-               GC_REFCOUNT(s)--;
+       if (!IS_INTERNED(s)) {
+               if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+                       ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+                       ret->len = len;
+                       zend_string_forget_hash_val(ret);
+                       return ret;
+               } else {
+                       GC_REFCOUNT(s)--;
+               }
+       }
+       ret = zend_string_alloc(len, persistent);
+       memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
+       return ret;
+}
+
+static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t len, int persistent)
+{
+       zend_string *ret;
+
+       ZEND_ASSERT(len >= s->len);
+       if (!IS_INTERNED(s)) {
+               if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+                       ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+                       ret->len = len;
+                       zend_string_forget_hash_val(ret);
+                       return ret;
+               } else {
+                       GC_REFCOUNT(s)--;
+               }
        }
+       ret = zend_string_alloc(len, persistent);
+       memcpy(ret->val, s->val, s->len + 1);
+       return ret;
+}
+
+static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size_t len, int persistent)
+{
+       zend_string *ret;
+
+       ZEND_ASSERT(len <= s->len);
+       if (!IS_INTERNED(s)) {
+               if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+                       ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+                       ret->len = len;
+                       zend_string_forget_hash_val(ret);
+                       return ret;
+               } else {
+                       GC_REFCOUNT(s)--;
+               }
+       }
+       ret = zend_string_alloc(len, persistent);
+       memcpy(ret->val, s->val, len + 1);
        return ret;
 }
 
@@ -177,18 +217,18 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
 {
        zend_string *ret;
 
-       if (IS_INTERNED(s)) {
-               ret = zend_string_safe_alloc(n, m, l, persistent);
-               memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
-       } else if (GC_REFCOUNT(s) == 1) {
-               ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
-               ret->len = (n * m) + l;
-               zend_string_forget_hash_val(ret);
-       } else {
-               ret = zend_string_safe_alloc(n, m, l, persistent);
-               memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
-               GC_REFCOUNT(s)--;
+       if (!IS_INTERNED(s)) {
+               if (GC_REFCOUNT(s) == 1) {
+                       ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
+                       ret->len = (n * m) + l;
+                       zend_string_forget_hash_val(ret);
+                       return ret;
+               } else {
+                       GC_REFCOUNT(s)--;
+               }
        }
+       ret = zend_string_safe_alloc(n, m, l, persistent);
+       memcpy(ret->val, s->val, ((n * m) + l > s->len ? s->len : ((n * m) + l)) + 1);
        return ret;
 }
 
index 1946dacda162223cd257e11c8675bbc623f3a2ed..3df1669c402a278faa41adf8cd23d522c9606420 100644 (file)
@@ -1661,7 +1661,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
        buf = zend_string_alloc(buf_len, 0);
        while ((real_len = strftime(buf->val, buf_len, format, &ta)) == buf_len || real_len == 0) {
                buf_len *= 2;
-               buf = zend_string_realloc(buf, buf_len, 0);
+               buf = zend_string_extend(buf, buf_len, 0);
                if (!--max_reallocs) {
                        break;
                }
@@ -1680,7 +1680,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
        }
 
        if (real_len && real_len != buf_len) {
-               buf = zend_string_realloc(buf, real_len, 0);
+               buf = zend_string_truncate(buf, real_len, 0);
                RETURN_NEW_STR(buf);
        }
        zend_string_free(buf);
index 81dfd5113604672620ca713e8369195e52c129a5..7621ce75aca5a530ec4f86ab339c648418e13bd0 100644 (file)
@@ -581,7 +581,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
 
        if (out_left < 8) {
                size_t pos = out_p - out_buffer->val;
-               out_buffer = zend_string_realloc(out_buffer, out_size + 8, 0);
+               out_buffer = zend_string_extend(out_buffer, out_size + 8, 0);
                out_p = out_buffer->val + pos;
                out_size += 7;
                out_left += 7;
@@ -640,7 +640,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
                                /* converted string is longer than out buffer */
                                bsz += in_len;
 
-                               out_buf = zend_string_realloc(out_buf, bsz, 0);
+                               out_buf = zend_string_extend(out_buf, bsz, 0);
                                out_p = out_buf->val;
                                out_p += out_size;
                                out_left = bsz - out_size;
@@ -662,7 +662,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
 
                        if (errno == E2BIG) {
                                bsz += 16;
-                               out_buf = zend_string_realloc(out_buf, bsz, 0);
+                               out_buf = zend_string_extend(out_buf, bsz, 0);
                                out_p = out_buf->val;
                                out_p += out_size;
                                out_left = bsz - out_size;
index eec5e74acb8fcc305c58eb73348542966a765ca2..d19126ff91b07093dbcad8f12719b2f4eb8d37c7 100644 (file)
@@ -1988,7 +1988,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
 
        newstr = zend_string_alloc(2 * escapestr_len, 0);
        newstr->len = mysql_real_escape_string(mysql->mysql, newstr->val, escapestr, escapestr_len);
-       newstr = zend_string_realloc(newstr, newstr->len, 0);
+       newstr = zend_string_truncate(newstr, newstr->len, 0);
 
        RETURN_NEW_STR(newstr);
 }
index 4fcff43c4f335ddb1f4900af45f1ac9c02422c04..d55de3275e00318fb0bf7697c16874ef0a290b5a 100644 (file)
@@ -983,7 +983,7 @@ int php_oci_bind_post_exec(void *data)
                 * binds, php_oci_bind_out_callback() should have allocated a
                 * new string that we can modify here.
                 */
-               Z_STR(bind->zval) = zend_string_realloc(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
+               Z_STR(bind->zval) = zend_string_extend(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
                Z_STRVAL(bind->zval)[ Z_STRLEN(bind->zval) ] = '\0';
        } else if (Z_TYPE(bind->zval) == IS_ARRAY) {
                int i;
index 24be4d266afe3ff4f6fa7afa2735c559574bf7a1..3f57183ed376d2ecb3aa8a6c2c3d901f7a9c1e72 100644 (file)
@@ -899,7 +899,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
                                memcpy(tmp->val, Z_STRVAL(ZEND_OP1_LITERAL(last_op)), old_len);
                                Z_STR(ZEND_OP1_LITERAL(last_op)) = tmp;
                        } else {
-                               Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_realloc(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
+                               Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_extend(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
                        }
                        Z_TYPE_INFO(ZEND_OP1_LITERAL(last_op)) = IS_STRING_EX;
                        memcpy(Z_STRVAL(ZEND_OP1_LITERAL(last_op)) + old_len, Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)));
@@ -954,7 +954,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
                                memcpy(tmp->val, Z_STRVAL(ZEND_OP2_LITERAL(src)), old_len);
                                Z_STR(ZEND_OP2_LITERAL(last_op)) = tmp;
                        } else {
-                               Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_realloc(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
+                               Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_extend(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
                        }
                        Z_TYPE_INFO(ZEND_OP2_LITERAL(last_op)) = IS_STRING_EX;
                        memcpy(Z_STRVAL(ZEND_OP2_LITERAL(src)) + old_len, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
index 6e769e06f0045e3fd2e6bfa9b125d8cf3f297551..8080823b09fb030a023c46cad92e2c5d00faf49b 100644 (file)
@@ -1158,7 +1158,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
                                        result = zend_string_alloc(alloc_len, 0);
                                } else {
                                        alloc_len = alloc_len + 2 * new_len;
-                                       result = zend_string_realloc(result, alloc_len, 0);
+                                       result = zend_string_extend(result, alloc_len, 0);
                                }
                        }
                        /* copy the part of the string before the match */
@@ -1779,7 +1779,7 @@ static PHP_FUNCTION(preg_quote)
        *q = '\0';
 
        /* Reallocate string and return it */
-       out_str = zend_string_realloc(out_str, q - out_str->val, 0);
+       out_str = zend_string_truncate(out_str, q - out_str->val, 0);
        RETURN_NEW_STR(out_str);
 }
 /* }}} */
index 4cbd218450050ce0333a13a3fdfd82a7e5c55d80..6e37f18287d10f9f277eb1d4dfa25dffed1e0e98 100644 (file)
@@ -4362,7 +4362,7 @@ PHP_FUNCTION(pg_escape_string)
                to->len = PQescapeString(to->val, from->val, from->len);
        }
 
-       to = zend_string_realloc(to, to->len, 0);
+       to = zend_string_truncate(to, to->len, 0);
        RETURN_NEW_STR(to);
 }
 /* }}} */
@@ -6048,7 +6048,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
                                                        str = zend_string_alloc(Z_STRLEN_P(val) * 2, 0);
                                                        /* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
                                                        str->len = PQescapeStringConn(pg_link, str->val, Z_STRVAL_P(val), Z_STRLEN_P(val), NULL);
-                                                       str = zend_string_realloc(str, str->len, 0);
+                                                       str = zend_string_truncate(str, str->len, 0);
                                                        ZVAL_NEW_STR(&new_val, str);
                                                        php_pgsql_add_quotes(&new_val, 1);
                                                }
index bed3823a4e7317635efc36fd5f13c6a3286bfed2..72a88be47c06396606859600ce30cbe1e4425bd5 100644 (file)
@@ -140,7 +140,7 @@ static string *string_printf(string *str, const char *format, ...)
                if (str->alloced < nlen) {
                        size_t old_len = str->buf->len;
                        str->alloced = nlen;
-                       str->buf = zend_string_realloc(str->buf, str->alloced, 0);
+                       str->buf = zend_string_extend(str->buf, str->alloced, 0);
                        str->buf->len = old_len;
                }
                memcpy(str->buf->val + str->buf->len, s_tmp, len + 1);
@@ -157,7 +157,7 @@ static string *string_write(string *str, char *buf, size_t len)
        if (str->alloced < nlen) {
                size_t old_len = str->buf->len;
                str->alloced = nlen;
-               str->buf = zend_string_realloc(str->buf, str->alloced, 0);
+               str->buf = zend_string_extend(str->buf, str->alloced, 0);
                str->buf->len = old_len;
        }
        memcpy(str->buf->val + str->buf->len, buf, len);
index 32172c803b5f309fa0705033e48bed9c5f786b6d..5f6c17af9a05ba7807c732ae7e4d0aff295ce6e5 100644 (file)
@@ -1177,7 +1177,7 @@ PHP_FUNCTION(socket_read)
                RETURN_EMPTY_STRING();
        }
 
-       tmpbuf = zend_string_realloc(tmpbuf, retval, 0);
+       tmpbuf = zend_string_truncate(tmpbuf, retval, 0);
        tmpbuf->len = retval;
        tmpbuf->val[tmpbuf->len] = '\0' ;
 
index f16734422b8d5c476dcd329f2e85490aa094fd59..78bdd6744ffbf93224966e842fd833cf87e66e0b 100644 (file)
@@ -552,7 +552,7 @@ PHP_FUNCTION(spl_autoload_register)
 
                if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
                        /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
-                       lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
+                       lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
                        memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
                        lc_name->val[lc_name->len] = '\0';
                        ZVAL_OBJ(&alfi.obj, obj_ptr);
@@ -663,7 +663,7 @@ PHP_FUNCTION(spl_autoload_unregister)
                        /* remove specific */
                        success = zend_hash_del(SPL_G(autoload_functions), lc_name);
                        if (success != SUCCESS && obj_ptr) {
-                               lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
+                               lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
                                memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
                                lc_name->val[lc_name->len] = '\0';
                                success = zend_hash_del(SPL_G(autoload_functions), lc_name);
index a98751ef12a852aaa17b51608683d66e1760579a..71dfc7c361672000466874cf94a491c644ac4f52 100644 (file)
@@ -326,7 +326,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str)
        if ((estimate - y) > 4096) {
                /* realloc if the estimate was way overill
                 * Arbitrary cutoff point of 4096 */
-               cmd = zend_string_realloc(cmd, y, 0);
+               cmd = zend_string_truncate(cmd, y, 0);
        }
 
        cmd->len = y;
@@ -392,7 +392,7 @@ PHPAPI zend_string *php_escape_shell_arg(char *str)
        if ((estimate - y) > 4096) {
                /* realloc if the estimate was way overill
                 * Arbitrary cutoff point of 4096 */
-               cmd = zend_string_realloc(cmd, y, 0);
+               cmd = zend_string_truncate(cmd, y, 0);
        }
        cmd->len = y;
        return cmd;
index cf4eee06570a60ad5d66e4329b920fdce3879103..4c0eeeebb94cee1f72f24f1236132b61b45160b6 100644 (file)
@@ -61,7 +61,7 @@ php_sprintf_appendchar(zend_string **buffer, size_t *pos, char add)
 {
        if (!*buffer || (*pos + 1) >= (*buffer)->len) {
                PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(), (*buffer)->len));
-               *buffer = zend_string_realloc(*buffer, (*buffer)->len << 1, 0);
+               *buffer = zend_string_extend(*buffer, (*buffer)->len << 1, 0);
        }
        PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
        (*buffer)->val[(*pos)++] = add;
@@ -101,7 +101,7 @@ php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add,
                        size <<= 1;
                }
                PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", size));
-               *buffer = zend_string_realloc(*buffer, size, 0);
+               *buffer = zend_string_extend(*buffer, size, 0);
        }
        if (alignment == ALIGN_RIGHT) {
                if ((neg || always_sign) && padding=='0') {
index cc94b0372f3ce948767b6a0435c58dcaa0fd092d..de29415cdf35f5b1d8f7239370e017196bfc7010 100644 (file)
@@ -142,7 +142,7 @@ static char Lookahead(char *word, int how_far)
  * could be one though; or more too). */
 #define Phonize(c)     { \
                                                if (p_idx >= max_buffer_len) { \
-                                                       *phoned_word = zend_string_realloc(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
+                                                       *phoned_word = zend_string_extend(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
                                                        max_buffer_len += 2; \
                                                } \
                                                (*phoned_word)->val[p_idx++] = c; \
@@ -151,7 +151,7 @@ static char Lookahead(char *word, int how_far)
 /* Slap a null character on the end of the phoned word */
 #define End_Phoned_Word        { \
                                                        if (p_idx == max_buffer_len) { \
-                                                               *phoned_word = zend_string_realloc(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
+                                                               *phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
                                                                max_buffer_len += 1; \
                                                        } \
                                                        (*phoned_word)->val[p_idx] = '\0'; \
index d19ef07e6669d6962a1ce9098f7ee8a2a28bef1f..26d1d2b6fc50b21bffe3a43c6751afd298a19aef 100644 (file)
@@ -187,7 +187,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt
                }
        }
        *d = '\0';
-       ret = zend_string_realloc(ret, d - (unsigned char*)ret->val, 0);
+       ret = zend_string_truncate(ret, d - (unsigned char*)ret->val, 0);
        return ret;
 }
 /* }}} */
index fbbb639dc212ec42183a112eed9074756085841b..01a87fe9196c8756866cb2f06cbaba7c052df259 100644 (file)
@@ -1004,7 +1004,7 @@ PHP_FUNCTION(wordwrap)
                for (current = 0; current < text->len; current++) {
                        if (chk <= 0) {
                                alloced += (size_t) (((text->len - current + 1)/linelength + 1) * breakchar_len) + 1;
-                               newtext = zend_string_realloc(newtext, alloced, 0);
+                               newtext = zend_string_extend(newtext, alloced, 0);
                                chk = (size_t) ((text->len - current)/linelength) + 1;
                        }
                        /* when we hit an existing break, copy to new buffer, and
@@ -1065,7 +1065,7 @@ PHP_FUNCTION(wordwrap)
 
                newtext->val[newtextlen] = '\0';
                /* free unused memory */
-               newtext = zend_string_realloc(newtext, newtextlen, 0);
+               newtext = zend_string_truncate(newtext, newtextlen, 0);
 
                RETURN_NEW_STR(newtext);
        }
@@ -2738,7 +2738,7 @@ PHP_FUNCTION(quotemeta)
 
        *q = '\0';
 
-       RETURN_NEW_STR(zend_string_realloc(str, q - str->val, 0));
+       RETURN_NEW_STR(zend_string_truncate(str, q - str->val, 0));
 }
 /* }}} */
 
@@ -3441,7 +3441,7 @@ PHPAPI zend_string *php_str_to_str(char *haystack, size_t length, char *needle,
                        }
 
                        *e = '\0';
-                       new_str = zend_string_realloc(new_str, e - s, 0);
+                       new_str = zend_string_truncate(new_str, e - s, 0);
                        return new_str;
                }
        } else if (needle_len > length || memcmp(haystack, needle, length)) {
@@ -3878,7 +3878,7 @@ PHPAPI zend_string *php_addcslashes(zend_string *str, int should_free, char *wha
        *target = 0;
        newlen = target - new_str->val;
        if (newlen < str->len * 4) {
-               new_str = zend_string_realloc(new_str, newlen, 0);
+               new_str = zend_string_truncate(new_str, newlen, 0);
        }
        if (should_free) {
                zend_string_release(str);
@@ -3954,7 +3954,7 @@ do_escape:
        }
 
        if (new_str->len - (target - new_str->val) > 16) {
-               new_str = zend_string_realloc(new_str, target - new_str->val, 0);
+               new_str = zend_string_truncate(new_str, target - new_str->val, 0);
        } else {
                new_str->len = target - new_str->val;
        }
@@ -5648,7 +5648,7 @@ PHP_FUNCTION(money_format)
        str->len = (size_t)res_len;
        str->val[str->len] = '\0';
 
-       RETURN_NEW_STR(zend_string_realloc(str, str->len, 0));
+       RETURN_NEW_STR(zend_string_truncate(str, str->len, 0));
 }
 /* }}} */
 #endif
index b2ffa3750e46ac0f9dc24dc9c588b6722b139615..1dceda148367c7e6edadd4d1878a9954811c0303 100644 (file)
@@ -524,7 +524,7 @@ PHPAPI zend_string *php_url_encode(char const *s, size_t len)
        }
        *to = '\0';
 
-       start = zend_string_realloc(start, to - (unsigned char*)start->val, 0);
+       start = zend_string_truncate(start, to - (unsigned char*)start->val, 0);
 
        return start;
 }
@@ -631,7 +631,7 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len)
                }
        }
        str->val[y] = '\0';
-       str = zend_string_realloc(str, y, 0);
+       str = zend_string_truncate(str, y, 0);
 
        return str;
 }
index afe9f7bea18ef31deadf2f36b6ff685eda71a1a7..91de87a194a3891a380839fffc7a5bad856428aa 100644 (file)
@@ -122,7 +122,7 @@ PHPAPI zend_string *php_uuencode(char *src, size_t src_len) /* {{{ */
        *p++ = '\n';
        *p = '\0';
 
-       dest = zend_string_realloc(dest, p - dest->val, 0);
+       dest = zend_string_truncate(dest, p - dest->val, 0);
        return dest;
 }
 /* }}} */
index 371b1e95d1630efc3e0a55024eab84b9633794e2..235efcdd18ae23722cec02da3ea61ab91b844b88 100644 (file)
@@ -991,7 +991,7 @@ static void php_wddx_process_data(void *user_data, const XML_Char *s, int len)
                                        zval_ptr_dtor(&ent->data);
                                        ZVAL_STRINGL(&ent->data, (char *)s, len);
                                } else {
-                                       Z_STR(ent->data) = zend_string_realloc(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
+                                       Z_STR(ent->data) = zend_string_extend(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
                                        memcpy(Z_STRVAL(ent->data) + Z_STRLEN(ent->data) - len, (char *)s, len);
                                        Z_STRVAL(ent->data)[Z_STRLEN(ent->data)] = '\0';
                                }
index 0ced7a22845aa951ed041e43ca4d63ab8e276f60..8a26a7ff5ccbae9b149c5cce426cd51889973cc6 100644 (file)
@@ -604,7 +604,7 @@ PHPAPI zend_string *xml_utf8_encode(const char *s, size_t len, const XML_Char *e
                s++;
        }
        str->val[str->len] = '\0';
-       str = zend_string_realloc(str, str->len, 0);
+       str = zend_string_truncate(str, str->len, 0);
        return str;
 }
 /* }}} */
@@ -644,7 +644,7 @@ PHPAPI zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Cha
        }
        str->val[str->len] = '\0';
        if (str->len < len) {
-               str = zend_string_realloc(str, str->len, 0);
+               str = zend_string_truncate(str, str->len, 0);
        }
 
        return str;
@@ -892,7 +892,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
                                        /* check if the current tag already has a value - if yes append to that! */
                                        if ((myval = zend_hash_str_find(Z_ARRVAL_P(parser->ctag), "value", sizeof("value") - 1))) {
                                                int newlen = Z_STRLEN_P(myval) + decoded_value->len;
-                                               Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
+                                               Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
                                                strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
                                                                decoded_value->val, decoded_value->len + 1);
                                                zend_string_release(decoded_value);
@@ -909,7 +909,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
                                                        if (!strcmp(Z_STRVAL_P(mytype), "cdata")) {
                                                                if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) {
                                                                        int newlen = Z_STRLEN_P(myval) + decoded_value->len;
-                                                                       Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
+                                                                       Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
                                                                        strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
                                                                                        decoded_value->val, decoded_value->len + 1);
                                                                        zend_string_release(decoded_value);
index 64eac450cdc38783f64796f61be235e2de136b04..b638ab43775aaaa07b55984bd386dff49bd23e20 100644 (file)
@@ -336,7 +336,7 @@ static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encod
 
                if (Z_STREAM_END == status) {
                        /* size buffer down to actual length */
-                       out = zend_string_realloc(out, Z.total_out, 0);
+                       out = zend_string_truncate(out, Z.total_out, 0);
                        out->val[out->len] = '\0';
                        return out;
                } else {
index 64b54707381d3c21c604c3c746b8fa27f8ae0937..0e95544fc14761169038dd8496c9e8d886dca639 100644 (file)
@@ -1477,7 +1477,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
        while ((ret = php_stream_read(src, ptr, max_len - len)))        {
                len += ret;
                if (len + min_room >= max_len) {
-                       result = zend_string_realloc(result, max_len + step, persistent);
+                       result = zend_string_extend(result, max_len + step, persistent);
                        max_len += step;
                        ptr = result->val + len;
                } else {
@@ -1485,7 +1485,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
                }
        }
        if (len) {
-               result = zend_string_realloc(result, len, persistent);
+               result = zend_string_truncate(result, len, persistent);
                result->val[len] = '\0';
        } else {
                zend_string_free(result);