Skip to content

Commit 9617c2a

Browse files
committed
Use cheaper zend_hash_find_ex() to handle IS_CONST index
1 parent bcd7352 commit 9617c2a

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_w(HashTable *ht, zend_long
147147

148148
static zval* ZEND_FASTCALL zend_jit_hash_lookup_rw(HashTable *ht, zend_string *str)
149149
{
150-
zval *retval = zend_hash_find(ht, str);
150+
zval *retval = zend_hash_find_ex(ht, str, 1);
151151

152152
if (retval) {
153153
if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT)) {
@@ -166,7 +166,7 @@ static zval* ZEND_FASTCALL zend_jit_hash_lookup_rw(HashTable *ht, zend_string *s
166166

167167
static zval* ZEND_FASTCALL zend_jit_hash_lookup_w(HashTable *ht, zend_string *str)
168168
{
169-
zval *retval = zend_hash_find(ht, str);
169+
zval *retval = zend_hash_find_ex(ht, str, 1);
170170

171171
if (retval) {
172172
if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT)) {
@@ -185,6 +185,7 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_strin
185185
{
186186
zend_ulong idx;
187187
register const char *tmp = str->val;
188+
zval *retval;
188189

189190
do {
190191
if (*tmp > '9') {
@@ -199,8 +200,7 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_strin
199200
}
200201
}
201202
if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
202-
zval *retval = zend_hash_index_find(ht, idx);
203-
203+
retval = zend_hash_index_find(ht, idx);
204204
if (!retval) {
205205
zend_error(E_NOTICE,"Undefined index: %s", ZSTR_VAL(str));
206206
retval = zend_hash_index_update(ht, idx, &EG(uninitialized_zval));
@@ -209,13 +209,27 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_strin
209209
}
210210
} while (0);
211211

212-
return zend_jit_hash_lookup_rw(ht, str);
212+
retval = zend_hash_find(ht, str);
213+
if (retval) {
214+
if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT)) {
215+
retval = Z_INDIRECT_P(retval);
216+
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
217+
zend_error(E_NOTICE,"Undefined index: %s", ZSTR_VAL(str));
218+
ZVAL_NULL(retval);
219+
}
220+
}
221+
} else {
222+
zend_error(E_NOTICE,"Undefined index: %s", ZSTR_VAL(str));
223+
retval = zend_hash_update(ht, str, &EG(uninitialized_zval));
224+
}
225+
return retval;
213226
}
214227

215228
static zval* ZEND_FASTCALL zend_jit_symtable_lookup_w(HashTable *ht, zend_string *str)
216229
{
217230
zend_ulong idx;
218231
register const char *tmp = str->val;
232+
zval *retval;
219233

220234
do {
221235
if (*tmp > '9') {
@@ -230,16 +244,26 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_w(HashTable *ht, zend_string
230244
}
231245
}
232246
if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
233-
zval *retval = zend_hash_index_find(ht, idx);
234-
247+
retval = zend_hash_index_find(ht, idx);
235248
if (!retval) {
236249
retval = zend_hash_index_add_new(ht, idx, &EG(uninitialized_zval));
237250
}
238251
return retval;
239252
}
240253
} while (0);
241254

242-
return zend_jit_hash_lookup_w(ht, str);
255+
retval = zend_hash_find(ht, str);
256+
if (retval) {
257+
if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT)) {
258+
retval = Z_INDIRECT_P(retval);
259+
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
260+
ZVAL_NULL(retval);
261+
}
262+
}
263+
} else {
264+
retval = zend_hash_add_new(ht, str, &EG(uninitialized_zval));
265+
}
266+
return retval;
243267
}
244268

245269
static void ZEND_FASTCALL zend_jit_undefined_op_helper(uint32_t var)

0 commit comments

Comments
 (0)