Skip to content

Commit 2a2f42c

Browse files
committed
Optimize out usless conditions used by specializer
1 parent 04b26ba commit 2a2f42c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Zend/zend_execute.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
5858
{
5959
zend_refcounted *ref = NULL;
6060

61-
if ((value_type & (IS_VAR|IS_CV)) && Z_ISREF_P(value)) {
61+
if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
6262
ref = Z_COUNTED_P(value);
6363
value = Z_REFVAL_P(value);
6464
}
@@ -78,7 +78,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
7878
Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
7979
return variable_ptr;
8080
}
81-
if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) {
81+
if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && variable_ptr == value) {
8282
return variable_ptr;
8383
}
8484
garbage = Z_COUNTED_P(variable_ptr);
@@ -93,7 +93,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
9393
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
9494
Z_ADDREF_P(variable_ptr);
9595
}
96-
} else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
96+
} else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
9797
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
9898
efree_size(ref, sizeof(zend_reference));
9999
} else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
@@ -122,7 +122,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
122122
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
123123
Z_ADDREF_P(variable_ptr);
124124
}
125-
} else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
125+
} else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
126126
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
127127
efree_size(ref, sizeof(zend_reference));
128128
} else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {

Zend/zend_portability.h

+8
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ char *alloca();
250250
# define HAVE_BUILTIN_CONSTANT_P
251251
#endif
252252

253+
#ifdef HAVE_BUILTIN_CONSTANT_P
254+
# define ZEND_CONST_COND(_condition, _default) \
255+
(__builtin_constant_p(_condition) ? (_condition) : (_default))
256+
#else
257+
# define ZEND_CONST_COND(_condition, _default) \
258+
(_default)
259+
#endif
260+
253261
#if ZEND_DEBUG
254262
# define zend_always_inline inline
255263
# define zend_never_inline

0 commit comments

Comments
 (0)