diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-04-16 14:45:08 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-04-16 14:45:08 +0300 |
commit | e38ed4c28ffe56f910626870667b374ac5ad1481 (patch) | |
tree | c6681c4d7f855cb94515930b1c45aee1a1ae4251 /Zend/zend_smart_str.h | |
parent | 05232cc810b39ff6f5a0307119bd76a548fe34be (diff) | |
download | php-git-e38ed4c28ffe56f910626870667b374ac5ad1481.tar.gz |
Changed zend_smart_str allocation granularity to do the better job together with Zend MM and avoid useless calls to erealloc().
The actual reallocation routiones are seprated from inlined code to reduce code size.
Diffstat (limited to 'Zend/zend_smart_str.h')
-rw-r--r-- | Zend/zend_smart_str.h | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/Zend/zend_smart_str.h b/Zend/zend_smart_str.h index c18b133dfe..7eae04e892 100644 --- a/Zend/zend_smart_str.h +++ b/Zend/zend_smart_str.h @@ -22,14 +22,6 @@ #include <zend.h> #include "zend_smart_str_public.h" -#ifndef SMART_STR_PREALLOC -#define SMART_STR_PREALLOC 128 -#endif - -#ifndef SMART_STR_START_SIZE -#define SMART_STR_START_SIZE 78 -#endif - #define smart_str_appends_ex(dest, src, what) \ smart_str_appendl_ex((dest), (src), strlen(src), (what)) #define smart_str_appends(dest, src) \ @@ -49,23 +41,28 @@ #define smart_str_append_unsigned(dest, val) \ smart_str_append_unsigned_ex((dest), (val), 0) +BEGIN_EXTERN_C() + +ZEND_API void ZEND_FASTCALL smart_str_erealloc(smart_str *str, size_t len); +ZEND_API void ZEND_FASTCALL smart_str_realloc(smart_str *str, size_t len); + +END_EXTERN_C() + 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; + if (UNEXPECTED(!str->s)) { + goto do_smart_str_realloc; } else { - newlen = str->s->len + len; - if (newlen >= str->a) { - str->a = newlen + SMART_STR_PREALLOC; - str->s = (zend_string *) perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent); + len += str->s->len; + if (UNEXPECTED(len >= str->a)) { +do_smart_str_realloc: + if (persistent) { + smart_str_realloc(str, len); + } else { + smart_str_erealloc(str, len); + } } } - return newlen; + return len; } static zend_always_inline void smart_str_free(smart_str *str) { |