Skip to content

Commit cfd76b0

Browse files
committed
Use faster API too look up property info in object handlers
We have the proprerty offset here and know it's valid, so we can use our property helper table to fetch it, rather than doing a full property info lookup.
1 parent dcc8ea8 commit cfd76b0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Zend/zend_object_handlers.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,16 @@ ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *membe
629629
}
630630
/* }}} */
631631

632+
static zend_always_inline zend_property_info *prop_info_for_offset(
633+
zend_object *obj, uint32_t prop_offset, void **cache_slot) {
634+
if (cache_slot) {
635+
return cache_slot[2];
636+
} else {
637+
zend_property_info *info = zend_get_property_info_for_slot(obj, OBJ_PROP(obj, prop_offset));
638+
return (info && info->type) ? info : NULL;
639+
}
640+
}
641+
632642
ZEND_API zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
633643
{
634644
zend_object *zobj;
@@ -743,7 +753,8 @@ ZEND_API zval *zend_std_read_property(zval *object, zval *member, int type, void
743753

744754
if (UNEXPECTED(ZEND_CLASS_HAS_TYPE_HINTS(zobj->ce) &&
745755
IS_VALID_PROPERTY_OFFSET(property_offset) &&
746-
(prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot)))) {
756+
(prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot)))
757+
) {
747758
zend_verify_prop_assignable_by_ref(prop_info, retval, (zobj->ce->__get->common.fn_flags & ZEND_ACC_STRICT_TYPES) != 0);
748759
}
749760

@@ -760,7 +771,7 @@ ZEND_API zval *zend_std_read_property(zval *object, zval *member, int type, void
760771

761772
if (type != BP_VAR_IS) {
762773
if (IS_VALID_PROPERTY_OFFSET(property_offset) &&
763-
(prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot))) {
774+
(prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot))) {
764775
zend_throw_error(NULL, "Typed property %s::$%s must not be accessed before initialization",
765776
ZSTR_VAL(prop_info->ce->name),
766777
ZSTR_VAL(name));
@@ -793,7 +804,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
793804
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
794805
variable_ptr = OBJ_PROP(zobj, property_offset);
795806
if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
796-
zend_property_info *prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot);
807+
zend_property_info *prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot);
797808

798809
Z_TRY_ADDREF_P(value);
799810

@@ -858,7 +869,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
858869

859870
variable_ptr = OBJ_PROP(zobj, property_offset);
860871

861-
if (UNEXPECTED(prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot))) {
872+
if (UNEXPECTED(prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot))) {
862873
ZVAL_COPY_VALUE(&tmp, value);
863874
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
864875
zval_ptr_dtor(value);

0 commit comments

Comments
 (0)