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.
This commit is contained in:
twosee 2020-06-08 18:45:01 +08:00 committed by Nikita Popov
parent 543684e796
commit 83a77015ad
16 changed files with 107 additions and 126 deletions

View file

@ -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 {