]> granicus.if.org Git - php/commitdiff
Reduce cost for references to strings and resources
authorDmitry Stogov <dmitry@zend.com>
Wed, 10 Jul 2019 09:27:59 +0000 (12:27 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 10 Jul 2019 09:27:59 +0000 (12:27 +0300)
Zend/zend_gc.h
Zend/zend_types.h

index e83e874e07f7fc39bec2e94559a171bf1d580170..4baca8fe33966648eebc0066818e483e4803436f 100644 (file)
@@ -74,7 +74,7 @@ static zend_always_inline void gc_check_possible_root(zend_refcounted *ref)
        if (GC_TYPE_INFO(ref) == IS_REFERENCE) {
                zval *zv = &((zend_reference*)ref)->val;
 
-               if (!Z_REFCOUNTED_P(zv)) {
+               if (!Z_COLLECTABLE_P(zv)) {
                        return;
                }
                ref = Z_COUNTED_P(zv);
index 3f6e1c1402b7199f3c8ef2cfa5b81d135c3de2e7..a018c43b81325e96d0d1564f4da061a3c839b460 100644 (file)
@@ -555,9 +555,11 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
 
 /* zval.u1.v.type_flags */
 #define IS_TYPE_REFCOUNTED                     (1<<0)
+#define IS_TYPE_COLLECTABLE                    (1<<1)
 
 #if 1
 /* This optimized version assumes that we have a single "type_flag" */
+/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */
 # define Z_TYPE_INFO_REFCOUNTED(t)     (((t) & Z_TYPE_FLAGS_MASK) != 0)
 #else
 # 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) {
 #define IS_INTERNED_STRING_EX          IS_STRING
 
 #define IS_STRING_EX                           (IS_STRING         | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
-#define IS_ARRAY_EX                                    (IS_ARRAY          | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
-#define IS_OBJECT_EX                           (IS_OBJECT         | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
+#define IS_ARRAY_EX                                    (IS_ARRAY          | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT) | (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT))
+#define IS_OBJECT_EX                           (IS_OBJECT         | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT) | (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT))
 #define IS_RESOURCE_EX                         (IS_RESOURCE       | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
 #define IS_REFERENCE_EX                                (IS_REFERENCE      | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT))
 
@@ -624,12 +626,16 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
 
 #if 1
 /* This optimized version assumes that we have a single "type_flag" */
+/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */
 #define Z_REFCOUNTED(zval)                     (Z_TYPE_FLAGS(zval) != 0)
 #else
 #define Z_REFCOUNTED(zval)                     ((Z_TYPE_FLAGS(zval) & IS_TYPE_REFCOUNTED) != 0)
 #endif
 #define Z_REFCOUNTED_P(zval_p)         Z_REFCOUNTED(*(zval_p))
 
+#define Z_COLLECTABLE(zval)                    ((Z_TYPE_FLAGS(zval) & IS_TYPE_COLLECTABLE) != 0)
+#define Z_COLLECTABLE_P(zval_p)                Z_COLLECTABLE(*(zval_p))
+
 /* deprecated: (COPYABLE is the same as IS_ARRAY) */
 #define Z_COPYABLE(zval)                       (Z_TYPE(zval) == IS_ARRAY)
 #define Z_COPYABLE_P(zval_p)           Z_COPYABLE(*(zval_p))