Skip to content

Optimize DOM property access #15626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,31 @@ static zval *dom_get_property_ptr_ptr(zend_object *object, zend_string *name, in
return NULL;
}

static zend_always_inline const dom_prop_handler *dom_get_prop_handler(const dom_object *obj, zend_string *name, void **cache_slot)
{
const dom_prop_handler *hnd = NULL;

if (obj->prop_handler != NULL) {
if (cache_slot) {
hnd = *cache_slot;
}
if (!hnd) {
hnd = zend_hash_find_ptr(obj->prop_handler, name);
if (cache_slot) {
*cache_slot = (void *) hnd;
}
}
}

return hnd;
}

/* {{{ dom_read_property */
zval *dom_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
{
dom_object *obj = php_dom_obj_from_obj(object);
zval *retval;
dom_prop_handler *hnd = NULL;

if (obj->prop_handler != NULL) {
hnd = zend_hash_find_ptr(obj->prop_handler, name);
}
const dom_prop_handler *hnd = dom_get_prop_handler(obj, name, cache_slot);

if (hnd) {
int ret = hnd->read_func(obj, rv);
Expand All @@ -394,19 +409,25 @@ zval *dom_read_property(zend_object *object, zend_string *name, int type, void *
zval *dom_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
{
dom_object *obj = php_dom_obj_from_obj(object);
dom_prop_handler *hnd = NULL;

if (obj->prop_handler != NULL) {
hnd = zend_hash_find_ptr(obj->prop_handler, name);
}
const dom_prop_handler *hnd = dom_get_prop_handler(obj, name, cache_slot);

if (hnd) {
if (!hnd->write_func) {
if (UNEXPECTED(!hnd->write_func)) {
zend_readonly_property_modification_error_ex(ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
return &EG(error_zval);
}

zend_property_info *prop = zend_get_property_info(object->ce, name, /* silent */ true);
zend_property_info *prop = NULL;
if (cache_slot) {
prop = *(cache_slot + 1);
}
if (!prop) {
prop = zend_get_property_info(object->ce, name, /* silent */ true);
if (cache_slot) {
*(cache_slot + 1) = prop;
}
}

ZEND_ASSERT(prop && ZEND_TYPE_IS_SET(prop->type));
zval tmp;
ZVAL_COPY(&tmp, value);
Expand Down
Loading