diff options
| author | Dmitry Stogov <dmitry@zend.com> | 2017-11-24 12:03:59 +0300 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@zend.com> | 2017-11-24 12:03:59 +0300 |
| commit | ed7f39672175e903e33745071dd82823be08ef31 (patch) | |
| tree | bc98c3ecd4d064f2492426447b8c610de735c9ce | |
| parent | 33b094479b7d2a61ecee52e7ce2bd389426349e9 (diff) | |
| download | php-git-ed7f39672175e903e33745071dd82823be08ef31.tar.gz | |
Avoid second hash value check
| -rw-r--r-- | Zend/zend_hash.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index c14cca78bb..5936b922dc 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -546,9 +546,19 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s if (UNEXPECTED(!(ht->u.flags & HASH_FLAG_INITIALIZED))) { CHECK_INIT(ht, 0); + if (!ZSTR_IS_INTERNED(key)) { + zend_string_addref(key); + ht->u.flags &= ~HASH_FLAG_STATIC_KEYS; + zend_string_hash_val(key); + } goto add_to_hash; } else if (ht->u.flags & HASH_FLAG_PACKED) { zend_hash_packed_to_hash(ht); + if (!ZSTR_IS_INTERNED(key)) { + zend_string_addref(key); + ht->u.flags &= ~HASH_FLAG_STATIC_KEYS; + zend_string_hash_val(key); + } } else if ((flag & HASH_ADD_NEW) == 0) { p = zend_hash_find_bucket(ht, key); @@ -582,6 +592,14 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s ZVAL_COPY_VALUE(data, pData); return data; } + if (!ZSTR_IS_INTERNED(key)) { + zend_string_addref(key); + ht->u.flags &= ~HASH_FLAG_STATIC_KEYS; + } + } else if (!ZSTR_IS_INTERNED(key)) { + zend_string_addref(key); + ht->u.flags &= ~HASH_FLAG_STATIC_KEYS; + zend_string_hash_val(key); } ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ @@ -595,11 +613,6 @@ add_to_hash: zend_hash_iterators_update(ht, HT_INVALID_IDX, idx); p = ht->arData + idx; p->key = key; - if (!ZSTR_IS_INTERNED(key)) { - zend_string_addref(key); - ht->u.flags &= ~HASH_FLAG_STATIC_KEYS; - zend_string_hash_val(key); - } p->h = h = ZSTR_H(key); ZVAL_COPY_VALUE(&p->val, pData); nIndex = h | ht->nTableMask; |
