From cdeebfd4afd270a7628344b544356f3d15c50372 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 12 Sep 2018 23:47:52 +0300 Subject: [PATCH] Avoid unnecesury iterations over parent classes, in case of no overriden private properties. --- Zend/zend_object_handlers.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index d36ed968f9..8d0756eb30 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -63,13 +63,14 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */ if (!zobj->properties) { zend_property_info *prop_info; zend_class_entry *ce = zobj->ce; + uint32_t flags = 0; zobj->properties = zend_new_array(ce->default_properties_count); if (ce->default_properties_count) { zend_hash_real_init_mixed(zobj->properties); ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { - if (/*prop_info->ce == ce &&*/ - (prop_info->flags & ZEND_ACC_STATIC) == 0) { + if (!(prop_info->flags & ZEND_ACC_STATIC)) { + flags |= prop_info->flags; if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) { HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND; @@ -79,22 +80,24 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */ OBJ_PROP(zobj, prop_info->offset)); } } ZEND_HASH_FOREACH_END(); - while (ce->parent && ce->parent->default_properties_count) { - ce = ce->parent; - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { - if (prop_info->ce == ce && - (prop_info->flags & ZEND_ACC_STATIC) == 0 && - (prop_info->flags & ZEND_ACC_PRIVATE) != 0) { - zval zv; - - if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) { - HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND; + if (flags & ZEND_ACC_CHANGED) { + while (ce->parent && ce->parent->default_properties_count) { + ce = ce->parent; + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { + if (prop_info->ce == ce && + !(prop_info->flags & ZEND_ACC_STATIC) && + (prop_info->flags & ZEND_ACC_PRIVATE)) { + zval zv; + + if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) { + HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND; + } + + ZVAL_INDIRECT(&zv, OBJ_PROP(zobj, prop_info->offset)); + zend_hash_add(zobj->properties, prop_info->name, &zv); } - - ZVAL_INDIRECT(&zv, OBJ_PROP(zobj, prop_info->offset)); - zend_hash_add(zobj->properties, prop_info->name, &zv); - } - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } } } } -- 2.40.0