From: Dmitry Stogov Date: Mon, 7 May 2018 21:22:04 +0000 (+0300) Subject: micro optimization X-Git-Tag: php-7.3.0alpha1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=858d545ce6c17f1cb7c81f3c563e36a9a602438c;p=php micro optimization --- diff --git a/Zend/zend_string.c b/Zend/zend_string.c index f32397afa7..2cfe329fe4 100644 --- a/Zend/zend_string.c +++ b/Zend/zend_string.c @@ -48,6 +48,11 @@ ZEND_API zend_string *zend_empty_string = NULL; ZEND_API zend_string *zend_one_char_string[256]; ZEND_API zend_string **zend_known_strings = NULL; +ZEND_API zend_ulong ZEND_FASTCALL zend_string_hash_func(zend_string *str) +{ + return ZSTR_H(str) = zend_hash_func(ZSTR_VAL(str), ZSTR_LEN(str)); +} + ZEND_API zend_ulong ZEND_FASTCALL zend_hash_func(const char *str, size_t len) { return zend_inline_hash_func(str, len); diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 99674cd5da..fe2a7475c4 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -32,6 +32,7 @@ typedef zend_string *(ZEND_FASTCALL *zend_string_init_interned_func_t)(const cha ZEND_API extern zend_new_interned_string_func_t zend_new_interned_string; ZEND_API extern zend_string_init_interned_func_t zend_string_init_interned; +ZEND_API zend_ulong ZEND_FASTCALL zend_string_hash_func(zend_string *str); ZEND_API zend_ulong ZEND_FASTCALL zend_hash_func(const char *str, size_t len); ZEND_API zend_string* ZEND_FASTCALL zend_interned_string_find_permanent(zend_string *str); @@ -97,10 +98,7 @@ END_EXTERN_C() static zend_always_inline zend_ulong zend_string_hash_val(zend_string *s) { - if (!ZSTR_H(s)) { - ZSTR_H(s) = zend_hash_func(ZSTR_VAL(s), ZSTR_LEN(s)); - } - return ZSTR_H(s); + return ZSTR_H(s) ? ZSTR_H(s) : zend_string_hash_func(s); } static zend_always_inline void zend_string_forget_hash_val(zend_string *s) diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c index 9d83791840..b2f463c65a 100644 --- a/ext/opcache/Optimizer/compact_literals.c +++ b/ext/opcache/Optimizer/compact_literals.c @@ -99,7 +99,7 @@ static uint32_t add_static_slot(HashTable *hash, Z_STRVAL_P(prop_name), Z_STRLEN_P(prop_name) + 1); - ZSTR_H(key) = zend_hash_func(ZSTR_VAL(key), ZSTR_LEN(key)); + ZSTR_H(key) = zend_string_hash_func(key); ZSTR_H(key) += kind; pos = zend_hash_find(hash, key);