Skip to content

Commit 89c6118

Browse files
committed
micro-optimization
1 parent 7279a66 commit 89c6118

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

Zend/zend_hash.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -730,25 +730,19 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s
730730
IS_CONSISTENT(ht);
731731
HT_ASSERT_RC1(ht);
732732

733+
if (!ZSTR_IS_INTERNED(key)) {
734+
zend_string_hash_val(key);
735+
}
736+
733737
if (UNEXPECTED(HT_FLAGS(ht) & (HASH_FLAG_UNINITIALIZED|HASH_FLAG_PACKED))) {
734738
if (EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) {
735739
zend_hash_real_init_mixed(ht);
736-
if (!ZSTR_IS_INTERNED(key)) {
737-
zend_string_addref(key);
738-
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
739-
zend_string_hash_val(key);
740-
}
741740
goto add_to_hash;
742741
} else {
743742
zend_hash_packed_to_hash(ht);
744-
if (!ZSTR_IS_INTERNED(key)) {
745-
zend_string_addref(key);
746-
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
747-
zend_string_hash_val(key);
748-
}
749743
}
750744
} else if ((flag & HASH_ADD_NEW) == 0 || ZEND_DEBUG) {
751-
p = zend_hash_find_bucket(ht, key, 0);
745+
p = zend_hash_find_bucket(ht, key, 1);
752746

753747
if (p) {
754748
zval *data;
@@ -781,19 +775,15 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s
781775
ZVAL_COPY_VALUE(data, pData);
782776
return data;
783777
}
784-
if (!ZSTR_IS_INTERNED(key)) {
785-
zend_string_addref(key);
786-
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
787-
}
788-
} else if (!ZSTR_IS_INTERNED(key)) {
789-
zend_string_addref(key);
790-
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
791-
zend_string_hash_val(key);
792778
}
793779

794780
ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */
795781

796782
add_to_hash:
783+
if (!ZSTR_IS_INTERNED(key)) {
784+
zend_string_addref(key);
785+
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
786+
}
797787
idx = ht->nNumUsed++;
798788
ht->nNumOfElements++;
799789
arData = ht->arData;

0 commit comments

Comments
 (0)