Skip to content

Commit 05b3c28

Browse files
authored
Slightly optimize hash add_new for packed arrays (GH-21539)
No need to check for UNDEF, assume the index is undefined. This eliminates the offset calculation, lookup and type check. Though of course dwarfed by the conversion to a proper hash table.
1 parent 594e002 commit 05b3c28

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Zend/zend_hash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,10 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
11111111
if ((flag & (HASH_ADD_NEW|HASH_ADD_NEXT)) != (HASH_ADD_NEW|HASH_ADD_NEXT)
11121112
&& h < ht->nNumUsed) {
11131113
zv = ht->arPacked + h;
1114-
if (Z_TYPE_P(zv) != IS_UNDEF) {
1114+
if (flag & HASH_ADD_NEW) {
1115+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_UNDEF);
1116+
goto convert_to_hash;
1117+
} else if (Z_TYPE_P(zv) != IS_UNDEF) {
11151118
if (flag & HASH_LOOKUP) {
11161119
return zv;
11171120
}

0 commit comments

Comments
 (0)