Skip to content

Commit d57d74b

Browse files
committed
Reduce cost for references to strings and resources
1 parent 2bca35e commit d57d74b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Zend/zend_gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static zend_always_inline void gc_check_possible_root(zend_refcounted *ref)
7474
if (GC_TYPE_INFO(ref) == IS_REFERENCE) {
7575
zval *zv = &((zend_reference*)ref)->val;
7676

77-
if (!Z_REFCOUNTED_P(zv)) {
77+
if (!Z_COLLECTABLE_P(zv)) {
7878
return;
7979
}
8080
ref = Z_COUNTED_P(zv);

Zend/zend_types.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,11 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
555555

556556
/* zval.u1.v.type_flags */
557557
#define IS_TYPE_REFCOUNTED (1<<0)
558+
#define IS_TYPE_COLLECTABLE (1<<1)
558559

559560
#if 1
560561
/* This optimized version assumes that we have a single "type_flag" */
562+
/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */
561563
# define Z_TYPE_INFO_REFCOUNTED(t) (((t) & Z_TYPE_FLAGS_MASK) != 0)
562564
#else
563565
# define Z_TYPE_INFO_REFCOUNTED(t) (((t) & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) != 0)
@@ -567,8 +569,8 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
567569
#define IS_INTERNED_STRING_EX IS_STRING
568570

569571
#define IS_STRING_EX (IS_STRING | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
570-
#define IS_ARRAY_EX (IS_ARRAY | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
571-
#define IS_OBJECT_EX (IS_OBJECT | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
572+
#define IS_ARRAY_EX (IS_ARRAY | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT) | (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT))
573+
#define IS_OBJECT_EX (IS_OBJECT | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT) | (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT))
572574
#define IS_RESOURCE_EX (IS_RESOURCE | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
573575
#define IS_REFERENCE_EX (IS_REFERENCE | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
574576

@@ -624,12 +626,16 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
624626

625627
#if 1
626628
/* This optimized version assumes that we have a single "type_flag" */
629+
/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */
627630
#define Z_REFCOUNTED(zval) (Z_TYPE_FLAGS(zval) != 0)
628631
#else
629632
#define Z_REFCOUNTED(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_REFCOUNTED) != 0)
630633
#endif
631634
#define Z_REFCOUNTED_P(zval_p) Z_REFCOUNTED(*(zval_p))
632635

636+
#define Z_COLLECTABLE(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_COLLECTABLE) != 0)
637+
#define Z_COLLECTABLE_P(zval_p) Z_COLLECTABLE(*(zval_p))
638+
633639
/* deprecated: (COPYABLE is the same as IS_ARRAY) */
634640
#define Z_COPYABLE(zval) (Z_TYPE(zval) == IS_ARRAY)
635641
#define Z_COPYABLE_P(zval_p) Z_COPYABLE(*(zval_p))

0 commit comments

Comments
 (0)