From: Nikita Popov Date: Tue, 21 Jan 2020 15:28:38 +0000 (+0100) Subject: Simplify constant updating for properties X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12fec7a14ef28a8193e4563cb9ce71d81ada56c0;p=php 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. --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 34b97b67e7..8ca81fc7d0 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1030,7 +1030,6 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */ ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{ */ { if (!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) { - zend_class_entry *ce; zend_class_constant *c; zval *val; zend_property_info *prop_info; @@ -1056,39 +1055,33 @@ ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{ */ } } - ce = class_type; - while (ce) { - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { - if (prop_info->ce == ce) { - if (prop_info->flags & ZEND_ACC_STATIC) { - val = CE_STATIC_MEMBERS(class_type) + prop_info->offset; - } else { - val = (zval*)((char*)class_type->default_properties_table + prop_info->offset - OBJ_PROP_TO_OFFSET(0)); + ZEND_HASH_FOREACH_PTR(&class_type->properties_info, prop_info) { + if (prop_info->flags & ZEND_ACC_STATIC) { + val = CE_STATIC_MEMBERS(class_type) + prop_info->offset; + } else { + val = (zval*)((char*)class_type->default_properties_table + prop_info->offset - OBJ_PROP_TO_OFFSET(0)); + } + if (Z_TYPE_P(val) == IS_CONSTANT_AST) { + if (ZEND_TYPE_IS_SET(prop_info->type)) { + zval tmp; + + ZVAL_COPY(&tmp, val); + if (UNEXPECTED(zval_update_constant_ex(&tmp, prop_info->ce) != SUCCESS)) { + zval_ptr_dtor(&tmp); + return FAILURE; } - if (Z_TYPE_P(val) == IS_CONSTANT_AST) { - if (ZEND_TYPE_IS_SET(prop_info->type)) { - zval tmp; - - ZVAL_COPY(&tmp, val); - if (UNEXPECTED(zval_update_constant_ex(&tmp, ce) != SUCCESS)) { - zval_ptr_dtor(&tmp); - return FAILURE; - } - /* property initializers must always be evaluated with strict types */; - if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, /* strict */ 1))) { - zval_ptr_dtor(&tmp); - return FAILURE; - } - zval_ptr_dtor(val); - ZVAL_COPY_VALUE(val, &tmp); - } else if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) { - return FAILURE; - } + /* property initializers must always be evaluated with strict types */; + if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, /* strict */ 1))) { + zval_ptr_dtor(&tmp); + return FAILURE; } + zval_ptr_dtor(val); + ZVAL_COPY_VALUE(val, &tmp); + } else if (UNEXPECTED(zval_update_constant_ex(val, prop_info->ce) != SUCCESS)) { + return FAILURE; } - } ZEND_HASH_FOREACH_END(); - ce = ce->parent; - } + } + } ZEND_HASH_FOREACH_END(); class_type->ce_flags |= ZEND_ACC_CONSTANTS_UPDATED; }