Skip to content

Commit 7ae0a3e

Browse files
committed
Move everything over to the slot API
I originall thought this wasn't possible, but now that it turned out that object_handlers also always has slots available, we can do this.
1 parent 2188200 commit 7ae0a3e

File tree

4 files changed

+79
-174
lines changed

4 files changed

+79
-174
lines changed

Zend/zend_execute.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,24 @@ static zend_never_inline zend_bool zend_handle_fetch_obj_flags(
26032603
return 1;
26042604
}
26052605

2606+
static zend_always_inline zend_property_info *zend_object_fetch_property_type_info(
2607+
zend_object *obj, zval *slot)
2608+
{
2609+
zend_property_info *info;
2610+
2611+
if (EXPECTED(!ZEND_CLASS_HAS_TYPE_HINTS(obj->ce))) {
2612+
return NULL;
2613+
}
2614+
2615+
/* Not a declared property */
2616+
if (UNEXPECTED(slot < obj->properties_table ||
2617+
slot >= obj->properties_table + obj->ce->default_properties_count)) {
2618+
return NULL;
2619+
}
2620+
2621+
return zend_get_typed_property_info_for_slot(obj, slot);
2622+
}
2623+
26062624
static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type, uint32_t flags, zend_bool init_undef OPLINE_DC)
26072625
{
26082626
zval *ptr;
@@ -2669,9 +2687,8 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
26692687

26702688
ZVAL_INDIRECT(result, ptr);
26712689
if (flags && UNEXPECTED(zend_need_to_handle_fetch_obj_flags(flags, ptr))) {
2672-
zend_string *tmp_str, *prop_name = zval_get_tmp_string(prop_ptr, &tmp_str);
2673-
zend_property_info *prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(container), prop_name, NULL);
2674-
zend_tmp_string_release(tmp_str);
2690+
zend_property_info *prop_info =
2691+
zend_object_fetch_property_type_info(Z_OBJ_P(container), ptr);
26752692
if (prop_info && !zend_handle_fetch_obj_flags(result, ptr, prop_info, flags)) {
26762693
return;
26772694
}

Zend/zend_execute.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,6 @@ ZEND_API int ZEND_FASTCALL zend_do_fcall_overloaded(zend_execute_data *call, zva
441441

442442
#define ZEND_CLASS_HAS_TYPE_HINTS(ce) ((ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) == ZEND_ACC_HAS_TYPE_HINTS)
443443

444-
// TODO We might want to migrate this (or at least some of its uses) to the
445-
// zend_get_property_info_for_slot() API in the future.
446-
static zend_always_inline zend_property_info *zend_object_fetch_property_type_info(zend_class_entry *ce, zend_string *property, void **cache_slot)
447-
{
448-
zend_property_info *info;
449-
450-
/* if we have a cache_slot, let's assume it's valid. Callers task to ensure validity! */
451-
if (EXPECTED(cache_slot)) {
452-
return (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);
453-
}
454-
455-
if (EXPECTED(!ZEND_CLASS_HAS_TYPE_HINTS(ce))) {
456-
return NULL;
457-
}
458-
459-
info = zend_get_property_info(ce, property, 1);
460-
461-
if (info && info != ZEND_WRONG_PROPERTY_INFO && info->type) {
462-
return info;
463-
}
464-
465-
return NULL;
466-
}
467-
468444
zend_bool zend_verify_property_type(zend_property_info *info, zval *property, zend_bool strict);
469445
ZEND_COLD void zend_verify_property_type_error(zend_property_info *info, zval *property);
470446

Zend/zend_vm_def.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ ZEND_VM_C_LABEL(assign_op_object):
834834
ZVAL_NULL(EX_VAR(opline->result.var));
835835
}
836836
} else {
837+
zval *orig_zptr = zptr;
837838
zend_reference *ref;
838839
zend_bool is_typed_ref = 0;
839840

@@ -846,9 +847,7 @@ ZEND_VM_C_LABEL(assign_op_object):
846847
if (OP2_TYPE == IS_CONST) {
847848
prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
848849
} else {
849-
zend_string *tmp_str, *prop_name = zval_get_tmp_string(property, &tmp_str);
850-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), prop_name, NULL);
851-
zend_tmp_string_release(tmp_str);
850+
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), orig_zptr);
852851
}
853852
if (UNEXPECTED(prop_info || is_typed_ref)) {
854853
/* special case for typed properties */
@@ -1234,9 +1233,7 @@ ZEND_VM_C_LABEL(pre_incdec_object):
12341233
if (OP2_TYPE == IS_CONST) {
12351234
prop_info = (zend_property_info *) CACHED_PTR_EX(cache_slot + 2);
12361235
} else {
1237-
zend_string *tmp_str, *prop_name = zval_get_tmp_string(property, &tmp_str);
1238-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), prop_name, NULL);
1239-
zend_tmp_string_release(tmp_str);
1236+
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), zptr);
12401237
}
12411238
zend_pre_incdec_property_zval(zptr, prop_info, inc OPLINE_CC EXECUTE_DATA_CC);
12421239
}
@@ -1301,9 +1298,7 @@ ZEND_VM_C_LABEL(post_incdec_object):
13011298
if (OP2_TYPE == IS_CONST) {
13021299
prop_info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
13031300
} else {
1304-
zend_string *tmp_str, *prop_name = zval_get_tmp_string(property, &tmp_str);
1305-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(object), prop_name, NULL);
1306-
zend_tmp_string_release(tmp_str);
1301+
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), zptr);
13071302
}
13081303

13091304
zend_post_incdec_property_zval(zptr, prop_info, inc OPLINE_CC EXECUTE_DATA_CC);
@@ -2747,9 +2742,7 @@ ZEND_VM_HANDLER(200, ZEND_ASSIGN_OBJ_REF, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, C
27472742
if (OP2_TYPE == IS_CONST) {
27482743
prop_info = (zend_property_info *) CACHED_PTR_EX(cache_addr + 2);
27492744
} else {
2750-
zend_string *tmp_str, *prop_name = zval_get_tmp_string(property, &tmp_str);
2751-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(container), prop_name, NULL);
2752-
zend_tmp_string_release(tmp_str);
2745+
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(container), variable_ptr);
27532746
}
27542747

27552748
if (UNEXPECTED(prop_info)) {

0 commit comments

Comments
 (0)