diff options
author | Nikita Popov <nikic@php.net> | 2013-09-13 18:45:02 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2013-09-13 19:42:10 +0200 |
commit | 96b1c2145c2cd5e616dea191648c2d73af0239c9 (patch) | |
tree | c9c8ae54ec95874143310c11f05337d7b7de06ad /Zend/zend_constants.c | |
parent | d2950ac2791cd03559a58e78f5cd626283b9ee4d (diff) | |
download | php-git-96b1c2145c2cd5e616dea191648c2d73af0239c9.tar.gz |
Provide more macros for handling of interned strings
* str_erealloc behaves like erealloc for normal strings, but will
use emalloc+memcpy for interned strings.
* str_estrndup behaves like estrndup for normal strings, but will
not copy interned strings.
* str_strndup behaves like zend_strndup for normal strings, but
will not copy interned strings.
* str_efree_rel behaves like efree_rel for normal strings, but
will not free interned strings.
* str_hash will return INTERNED_HASH for interned strings and
compute it using zend_hash_func for normal strings.
Diffstat (limited to 'Zend/zend_constants.c')
-rw-r--r-- | Zend/zend_constants.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 594559d58b..a53af497cc 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -38,9 +38,7 @@ void free_zend_constant(zend_constant *c) void copy_zend_constant(zend_constant *c) { - if (!IS_INTERNED(c->name)) { - c->name = zend_strndup(c->name, c->name_len - 1); - } + c->name = str_strndup(c->name, c->name_len - 1); if (!(c->flags & CONST_PERSISTENT)) { zval_copy_ctor(&c->value); } @@ -474,7 +472,7 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) char *lowercase_name = NULL; char *name; int ret = SUCCESS; - ulong chash = 0; + ulong chash; #if 0 printf("Registering constant for module %d\n", c->module_number); @@ -486,23 +484,18 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) zend_str_tolower(lowercase_name, c->name_len-1); lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC); name = lowercase_name; - chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0; } else { char *slash = strrchr(c->name, '\\'); - if(slash) { + if (slash) { lowercase_name = estrndup(c->name, c->name_len-1); zend_str_tolower(lowercase_name, slash-c->name); lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC); name = lowercase_name; - - chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0; } else { name = c->name; } } - if (chash == 0) { - chash = zend_hash_func(name, c->name_len); - } + chash = str_hash(name, c->name_len-1); /* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */ if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__") @@ -521,8 +514,8 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) } ret = FAILURE; } - if (lowercase_name && !IS_INTERNED(lowercase_name)) { - efree(lowercase_name); + if (lowercase_name) { + str_efree(lowercase_name); } return ret; } |