Skip to content

Commit 43856d4

Browse files
committed
experiemtn
1 parent 7d551a8 commit 43856d4

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

Zend/zend_API.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,20 +1607,27 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
16071607
if (class_type->default_properties_count) {
16081608
zval *src = CE_DEFAULT_PROPERTIES_TABLE(class_type);
16091609
zval *dst = object->properties_table;
1610-
zval *end = src + class_type->default_properties_count;
16111610

1612-
if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
1613-
do {
1614-
ZVAL_COPY_OR_DUP_PROP(dst, src);
1615-
src++;
1616-
dst++;
1617-
} while (src != end);
1611+
if (!(class_type->ce_flags & ZEND_ACC_HAS_RC_PROPS)) {
1612+
// printf("fast path %s\n", class_type->name->val);
1613+
memcpy(dst, src, sizeof(zval) * class_type->default_properties_count);
16181614
} else {
1619-
do {
1620-
ZVAL_COPY_PROP(dst, src);
1621-
src++;
1622-
dst++;
1623-
} while (src != end);
1615+
// printf("slow path %s\n", class_type->name->val);
1616+
zval *end = src + class_type->default_properties_count;
1617+
1618+
if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
1619+
do {
1620+
ZVAL_COPY_OR_DUP_PROP(dst, src);
1621+
src++;
1622+
dst++;
1623+
} while (src != end);
1624+
} else {
1625+
do {
1626+
ZVAL_COPY_PROP(dst, src);
1627+
src++;
1628+
dst++;
1629+
} while (src != end);
1630+
}
16241631
}
16251632
}
16261633
}
@@ -4303,6 +4310,7 @@ static zend_always_inline bool is_persistent_class(zend_class_entry *ce) {
43034310
ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type) /* {{{ */
43044311
{
43054312
zend_property_info *property_info, *property_info_ptr;
4313+
// printf("decl prop %s\n", name->val);
43064314

43074315
if (ZEND_TYPE_IS_SET(type)) {
43084316
ce->ce_flags |= ZEND_ACC_HAS_TYPE_HINTS;
@@ -4378,6 +4386,11 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43784386
ce->properties_info_table[ce->default_properties_count - 1] = property_info;
43794387
}
43804388
}
4389+
// printf("%s %s\n", ce->name->val, name->val);
4390+
if (Z_REFCOUNTED_P(property)) {
4391+
// printf("refcounted\n");
4392+
ce->ce_flags |= ZEND_ACC_HAS_RC_PROPS;
4393+
}
43814394
property_default_ptr = &ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)];
43824395
ZVAL_COPY_VALUE(property_default_ptr, property);
43834396
Z_PROP_FLAG_P(property_default_ptr) = Z_ISUNDEF_P(property) ? IS_PROP_UNINIT : 0;

Zend/zend_compile.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ typedef struct _zend_oparray_context {
239239
/* or IS_CONSTANT_VISITED_MARK | | | */
240240
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
241241
/* | | | */
242-
/* Class Flags (unused: 30,31) | | | */
242+
/* Class Flags (unused: 31) | | | */
243243
/* =========== | | | */
244244
/* | | | */
245245
/* Special class types | | | */
@@ -304,6 +304,8 @@ typedef struct _zend_oparray_context {
304304
/* | | | */
305305
/* Class cannot be serialized or unserialized | | | */
306306
#define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
307+
/* Class has refcounted props | | | */
308+
#define ZEND_ACC_HAS_RC_PROPS (1 << 30) /* X | | | */
307309
/* | | | */
308310
/* Function Flags (unused: 29-30) | | | */
309311
/* ============== | | | */

Zend/zend_inheritance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,8 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
16721672
ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
16731673
}
16741674
}
1675-
ce->ce_flags |= parent_ce->ce_flags & (ZEND_HAS_STATIC_IN_METHODS | ZEND_ACC_HAS_TYPE_HINTS | ZEND_ACC_HAS_READONLY_PROPS | ZEND_ACC_USE_GUARDS | ZEND_ACC_NOT_SERIALIZABLE | ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES);
1675+
ce->ce_flags |= parent_ce->ce_flags & (ZEND_HAS_STATIC_IN_METHODS | ZEND_ACC_HAS_TYPE_HINTS | ZEND_ACC_HAS_READONLY_PROPS | ZEND_ACC_USE_GUARDS | ZEND_ACC_NOT_SERIALIZABLE | ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES | ZEND_ACC_HAS_RC_PROPS);
1676+
// printf("inherited %s from %s (%d)\n", ZSTR_VAL(ce->name), ZSTR_VAL(parent_ce->name), ce->ce_flags&ZEND_ACC_HAS_RC_PROPS);
16761677
}
16771678
/* }}} */
16781679

0 commit comments

Comments
 (0)