Skip to content

Commit 12fec7a

Browse files
committed
Simplify constant updating for properties
Instead of walking up the parent chain, use the scope stored in the property info. This way we only need to walk one list of property infos.
1 parent 7cb1a70 commit 12fec7a

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

Zend/zend_API.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */
10301030
ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{ */
10311031
{
10321032
if (!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
1033-
zend_class_entry *ce;
10341033
zend_class_constant *c;
10351034
zval *val;
10361035
zend_property_info *prop_info;
@@ -1056,39 +1055,33 @@ ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{ */
10561055
}
10571056
}
10581057

1059-
ce = class_type;
1060-
while (ce) {
1061-
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
1062-
if (prop_info->ce == ce) {
1063-
if (prop_info->flags & ZEND_ACC_STATIC) {
1064-
val = CE_STATIC_MEMBERS(class_type) + prop_info->offset;
1065-
} else {
1066-
val = (zval*)((char*)class_type->default_properties_table + prop_info->offset - OBJ_PROP_TO_OFFSET(0));
1058+
ZEND_HASH_FOREACH_PTR(&class_type->properties_info, prop_info) {
1059+
if (prop_info->flags & ZEND_ACC_STATIC) {
1060+
val = CE_STATIC_MEMBERS(class_type) + prop_info->offset;
1061+
} else {
1062+
val = (zval*)((char*)class_type->default_properties_table + prop_info->offset - OBJ_PROP_TO_OFFSET(0));
1063+
}
1064+
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
1065+
if (ZEND_TYPE_IS_SET(prop_info->type)) {
1066+
zval tmp;
1067+
1068+
ZVAL_COPY(&tmp, val);
1069+
if (UNEXPECTED(zval_update_constant_ex(&tmp, prop_info->ce) != SUCCESS)) {
1070+
zval_ptr_dtor(&tmp);
1071+
return FAILURE;
10671072
}
1068-
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
1069-
if (ZEND_TYPE_IS_SET(prop_info->type)) {
1070-
zval tmp;
1071-
1072-
ZVAL_COPY(&tmp, val);
1073-
if (UNEXPECTED(zval_update_constant_ex(&tmp, ce) != SUCCESS)) {
1074-
zval_ptr_dtor(&tmp);
1075-
return FAILURE;
1076-
}
1077-
/* property initializers must always be evaluated with strict types */;
1078-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, /* strict */ 1))) {
1079-
zval_ptr_dtor(&tmp);
1080-
return FAILURE;
1081-
}
1082-
zval_ptr_dtor(val);
1083-
ZVAL_COPY_VALUE(val, &tmp);
1084-
} else if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) {
1085-
return FAILURE;
1086-
}
1073+
/* property initializers must always be evaluated with strict types */;
1074+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, /* strict */ 1))) {
1075+
zval_ptr_dtor(&tmp);
1076+
return FAILURE;
10871077
}
1078+
zval_ptr_dtor(val);
1079+
ZVAL_COPY_VALUE(val, &tmp);
1080+
} else if (UNEXPECTED(zval_update_constant_ex(val, prop_info->ce) != SUCCESS)) {
1081+
return FAILURE;
10881082
}
1089-
} ZEND_HASH_FOREACH_END();
1090-
ce = ce->parent;
1091-
}
1083+
}
1084+
} ZEND_HASH_FOREACH_END();
10921085

10931086
class_type->ce_flags |= ZEND_ACC_CONSTANTS_UPDATED;
10941087
}

0 commit comments

Comments
 (0)