Skip to content

Commit 91f283a

Browse files
committed
micro-optimization
1 parent 3a031e0 commit 91f283a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

Zend/zend_execute.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3109,10 +3109,17 @@ static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) {
31093109
}
31103110
}
31113111

3112-
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, zend_uchar value_type, zend_bool strict, zend_refcounted *ref)
3112+
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, zend_uchar value_type, zend_bool strict)
31133113
{
31143114
zend_bool ret;
31153115
zval value;
3116+
zend_refcounted *ref = NULL;
3117+
3118+
if (Z_ISREF_P(orig_value)) {
3119+
ref = Z_COUNTED_P(orig_value);
3120+
orig_value = Z_REFVAL_P(orig_value);
3121+
}
3122+
31163123
ZVAL_COPY(&value, orig_value);
31173124
ret = zend_verify_ref_assignable_zval(Z_REF_P(variable_ptr), &value, strict);
31183125
variable_ptr = Z_REFVAL_P(variable_ptr);

Zend/zend_execute.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,17 @@ ZEND_API zend_bool zend_value_instanceof_static(zval *zv);
8686
ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop);
8787
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, zend_property_info *prop);
8888

89-
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *value, zend_uchar value_type, zend_bool strict, zend_refcounted *ref);
89+
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *value, zend_uchar value_type, zend_bool strict);
9090

91-
static zend_always_inline void zend_copy_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type, zend_refcounted *ref)
91+
static zend_always_inline void zend_copy_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
9292
{
93+
zend_refcounted *ref = NULL;
94+
95+
if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
96+
ref = Z_COUNTED_P(value);
97+
value = Z_REFVAL_P(value);
98+
}
99+
93100
ZVAL_COPY_VALUE(variable_ptr, value);
94101
if (ZEND_CONST_COND(value_type == IS_CONST, 0)) {
95102
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
@@ -110,20 +117,13 @@ static zend_always_inline void zend_copy_to_variable(zval *variable_ptr, zval *v
110117

111118
static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type, zend_bool strict)
112119
{
113-
zend_refcounted *ref = NULL;
114-
115-
if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
116-
ref = Z_COUNTED_P(value);
117-
value = Z_REFVAL_P(value);
118-
}
119-
120120
do {
121121
if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
122122
zend_refcounted *garbage;
123123

124124
if (Z_ISREF_P(variable_ptr)) {
125125
if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(variable_ptr)))) {
126-
return zend_assign_to_typed_ref(variable_ptr, value, value_type, strict, ref);
126+
return zend_assign_to_typed_ref(variable_ptr, value, value_type, strict);
127127
}
128128

129129
variable_ptr = Z_REFVAL_P(variable_ptr);
@@ -132,7 +132,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
132132
}
133133
}
134134
garbage = Z_COUNTED_P(variable_ptr);
135-
zend_copy_to_variable(variable_ptr, value, value_type, ref);
135+
zend_copy_to_variable(variable_ptr, value, value_type);
136136
if (GC_DELREF(garbage) == 0) {
137137
rc_dtor_func(garbage);
138138
} else { /* we need to split */
@@ -145,7 +145,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
145145
}
146146
} while (0);
147147

148-
zend_copy_to_variable(variable_ptr, value, value_type, ref);
148+
zend_copy_to_variable(variable_ptr, value, value_type);
149149
return variable_ptr;
150150
}
151151

0 commit comments

Comments
 (0)