Skip to content

Commit cbbd473

Browse files
committed
Separate slow code
1 parent 2d4bb4f commit cbbd473

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

Zend/zend_execute.c

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,34 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_s
20042004
zend_throw_error(NULL, "[] operator not supported for strings");
20052005
}
20062006

2007+
static zend_never_inline zend_uchar slow_index_convert(const zval *dim, zend_value *value)
2008+
{
2009+
switch (Z_TYPE_P(dim)) {
2010+
case IS_UNDEF:
2011+
ZVAL_UNDEFINED_OP2();
2012+
/* break missing intentionally */
2013+
case IS_NULL:
2014+
value->str = ZSTR_EMPTY_ALLOC();
2015+
return IS_STRING;
2016+
case IS_DOUBLE:
2017+
value->lval = zend_dval_to_lval(Z_DVAL_P(dim));
2018+
return IS_LONG;
2019+
case IS_RESOURCE:
2020+
zend_use_resource_as_offset(dim);
2021+
value->lval = Z_RES_HANDLE_P(dim);
2022+
return IS_LONG;
2023+
case IS_FALSE:
2024+
value->lval = 0;
2025+
return IS_LONG;
2026+
case IS_TRUE:
2027+
value->lval = 1;
2028+
return IS_LONG;
2029+
default:
2030+
zend_illegal_offset();
2031+
return IS_NULL;
2032+
}
2033+
}
2034+
20072035
static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type EXECUTE_DATA_DC)
20082036
{
20092037
zval *retval = NULL;
@@ -2082,33 +2110,21 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
20822110
break;
20832111
}
20842112
}
2113+
} else if (EXPECTED(Z_TYPE_P(dim) == IS_REFERENCE)) {
2114+
dim = Z_REFVAL_P(dim);
2115+
goto try_again;
20852116
} else {
2086-
switch (Z_TYPE_P(dim)) {
2087-
case IS_UNDEF:
2088-
ZVAL_UNDEFINED_OP2();
2089-
/* break missing intentionally */
2090-
case IS_NULL:
2091-
offset_key = ZSTR_EMPTY_ALLOC();
2092-
goto str_index;
2093-
case IS_DOUBLE:
2094-
hval = zend_dval_to_lval(Z_DVAL_P(dim));
2095-
goto num_index;
2096-
case IS_RESOURCE:
2097-
zend_use_resource_as_offset(dim);
2098-
hval = Z_RES_HANDLE_P(dim);
2099-
goto num_index;
2100-
case IS_FALSE:
2101-
hval = 0;
2102-
goto num_index;
2103-
case IS_TRUE:
2104-
hval = 1;
2105-
goto num_index;
2106-
case IS_REFERENCE:
2107-
dim = Z_REFVAL_P(dim);
2108-
goto try_again;
2109-
default:
2110-
zend_illegal_offset();
2111-
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
2117+
zend_value val;
2118+
zend_uchar t = slow_index_convert(dim, &val);
2119+
2120+
if (t == IS_STRING) {
2121+
offset_key = val.str;
2122+
goto str_index;
2123+
} else if (t == IS_LONG) {
2124+
hval = val.lval;
2125+
goto num_index;
2126+
} else {
2127+
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
21122128
NULL : &EG(uninitialized_zval);
21132129
}
21142130
}

0 commit comments

Comments
 (0)