Skip to content

Commit 353461a

Browse files
committed
Separate zend_array_type_info() to avoid loop inlining
1 parent 4e44599 commit 353461a

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,34 @@ static void emit_type_narrowing_warning(const zend_op_array *op_array, zend_ssa
20242024
zend_error(E_WARNING, "Narrowing occurred during type inference of %s. Please file a bug report on bugs.php.net", def_op_name);
20252025
}
20262026

2027+
ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv)
2028+
{
2029+
HashTable *ht = Z_ARRVAL_P(zv);
2030+
uint32_t tmp = MAY_BE_ARRAY;
2031+
zend_string *str;
2032+
zval *val;
2033+
2034+
if (Z_REFCOUNTED_P(zv)) {
2035+
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
2036+
} else {
2037+
tmp |= MAY_BE_RCN;
2038+
}
2039+
2040+
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) {
2041+
if (str) {
2042+
tmp |= MAY_BE_ARRAY_KEY_STRING;
2043+
} else {
2044+
tmp |= MAY_BE_ARRAY_KEY_LONG;
2045+
}
2046+
tmp |= 1 << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT);
2047+
} ZEND_HASH_FOREACH_END();
2048+
if (HT_IS_PACKED(ht)) {
2049+
tmp &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
2050+
}
2051+
return tmp;
2052+
}
2053+
2054+
20272055
ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int write, int insert)
20282056
{
20292057
uint32_t tmp = 0;

Zend/Optimizer/zend_inference.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,15 @@ DEFINE_SSA_OP_RANGE_OVERFLOW(op2)
152152
#define OP2_RANGE_UNDERFLOW() (_ssa_op2_range_underflow (op_array, ssa, opline, ssa_op))
153153
#define OP2_RANGE_OVERFLOW() (_ssa_op2_range_overflow (op_array, ssa, opline, ssa_op))
154154

155+
BEGIN_EXTERN_C()
156+
ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv);
157+
END_EXTERN_C()
158+
155159
static zend_always_inline uint32_t _const_op_type(const zval *zv) {
156160
if (Z_TYPE_P(zv) == IS_CONSTANT_AST) {
157161
return MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY;
158162
} else if (Z_TYPE_P(zv) == IS_ARRAY) {
159-
HashTable *ht = Z_ARRVAL_P(zv);
160-
uint32_t tmp = MAY_BE_ARRAY;
161-
zend_string *str;
162-
zval *val;
163-
164-
if (Z_REFCOUNTED_P(zv)) {
165-
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
166-
} else {
167-
tmp |= MAY_BE_RCN;
168-
}
169-
170-
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) {
171-
if (str) {
172-
tmp |= MAY_BE_ARRAY_KEY_STRING;
173-
} else {
174-
tmp |= MAY_BE_ARRAY_KEY_LONG;
175-
}
176-
tmp |= 1 << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT);
177-
} ZEND_HASH_FOREACH_END();
178-
if (HT_IS_PACKED(ht)) {
179-
tmp &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
180-
}
181-
return tmp;
163+
return zend_array_type_info(zv);
182164
} else {
183165
uint32_t tmp = (1 << Z_TYPE_P(zv));
184166

0 commit comments

Comments
 (0)