diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-21 16:28:38 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-21 16:29:56 +0100 |
commit | 12fec7a14ef28a8193e4563cb9ce71d81ada56c0 (patch) | |
tree | b45c10a66759a688240135105c0adfc17fa0d267 /Zend/zend_API.c | |
parent | 7cb1a706bb52ef31f979d1343338bda3163e5303 (diff) | |
download | php-git-12fec7a14ef28a8193e4563cb9ce71d81ada56c0.tar.gz |
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.
Diffstat (limited to 'Zend/zend_API.c')
-rw-r--r-- | Zend/zend_API.c | 55 |
1 files changed, 24 insertions, 31 deletions
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; } |