Skip to content

Commit 7b1f53d

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 f2a3d6b commit 7b1f53d

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));
@@ -792,7 +803,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
792803
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
793804
variable_ptr = OBJ_PROP(zobj, property_offset);
794805
if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
795-
zend_property_info *prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot);
806+
zend_property_info *prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot);
796807

797808
Z_TRY_ADDREF_P(value);
798809

@@ -867,7 +878,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
867878

868879
variable_ptr = OBJ_PROP(zobj, property_offset);
869880

870-
if (UNEXPECTED(prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), name, cache_slot))) {
881+
if (UNEXPECTED(prop_info = prop_info_for_offset(Z_OBJ_P(object), property_offset, cache_slot))) {
871882
ZVAL_COPY_VALUE(&tmp, value);
872883
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
873884
zval_ptr_dtor(value);

0 commit comments

Comments
 (0)