Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */
ZEND_FUNCTION(define)
{
zend_string *name;
zval *val, val_free;
zval *val;
bool non_cs = 0;
zend_constant c;

Expand All @@ -575,23 +575,16 @@ ZEND_FUNCTION(define)
zend_error(E_WARNING, "define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported");
}

ZVAL_UNDEF(&val_free);

if (Z_TYPE_P(val) == IS_ARRAY) {
if (Z_REFCOUNTED_P(val)) {
if (!validate_constant_array_argument(Z_ARRVAL_P(val), 2)) {
RETURN_THROWS();
} else {
copy_constant_array(&c.value, val);
goto register_constant;
}
if (Z_TYPE_P(val) == IS_ARRAY && Z_REFCOUNTED_P(val)) {
if (!validate_constant_array_argument(Z_ARRVAL_P(val), 2)) {
RETURN_THROWS();
} else {
copy_constant_array(&c.value, val);
}
} else {
ZVAL_COPY(&c.value, val);
}

ZVAL_COPY(&c.value, val);
zval_ptr_dtor(&val_free);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it more code size decrease and/or little perf gain ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just getting rid of confusing code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes this also makes a tiny code size decrease (but that was not the motivation). Perf is likely unchanged.


register_constant:
/* non persistent */
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
c.name = zend_string_copy(name);
Expand Down