diff options
author | twosee <twose@qq.com> | 2020-06-08 18:45:01 +0800 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-06-08 15:31:52 +0200 |
commit | 83a77015ad0dcd25d30342a08cbc8ec3de077305 (patch) | |
tree | 3039af88d8bb809f98698bc4bcb282da9f374a14 /main/php_variables.c | |
parent | 543684e7962073dcae3ecdd9504211876e630bec (diff) | |
download | php-git-83a77015ad0dcd25d30342a08cbc8ec3de077305.tar.gz |
Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.
Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.
Also add corresponding ZVAL_STRINGL_FAST etc macros.
Closes GH-5684.
Diffstat (limited to 'main/php_variables.c')
-rw-r--r-- | main/php_variables.c | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/main/php_variables.c b/main/php_variables.c index 89b3dbf2d6..0a1eb0b4cd 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -41,14 +41,8 @@ PHPAPI void php_register_variable_safe(const char *var, const char *strval, size zval new_entry; assert(strval != NULL); - /* Prepare value */ - if (str_len == 0) { - ZVAL_EMPTY_STRING(&new_entry); - } else if (str_len == 1) { - ZVAL_INTERNED_STR(&new_entry, ZSTR_CHAR((zend_uchar)*strval)); - } else { - ZVAL_NEW_STR(&new_entry, zend_string_init(strval, str_len, 0)); - } + ZVAL_STRINGL_FAST(&new_entry, strval, str_len); + php_register_variable_ex(var, &new_entry, track_vars_array); } @@ -552,13 +546,7 @@ static zend_always_inline void import_environment_variable(HashTable *ht, char * name_len = p - env; p++; len = strlen(p); - if (len == 0) { - ZVAL_EMPTY_STRING(&val); - } else if (len == 1) { - ZVAL_INTERNED_STR(&val, ZSTR_CHAR((zend_uchar)*p)); - } else { - ZVAL_NEW_STR(&val, zend_string_init(p, len, 0)); - } + ZVAL_STRINGL_FAST(&val, p, len); if (ZEND_HANDLE_NUMERIC_STR(env, name_len, idx)) { zend_hash_index_update(ht, idx, &val); } else { |