Skip to content

Commit 6a19160

Browse files
Avoid unnecessary concatenation in zend_named_reflection_type_to_string()
When a type corresponds to an iterator that may be null, the string representation is known ahead of time to be "?iterable". Use `ZSTR_INIT_LITERAL()` rather than building up a string with `zend_string_concat2()` from a "?" and the "iterable" known string.
1 parent 5dfab10 commit 6a19160

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

ext/reflection/php_reflection.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,11 +3074,10 @@ ZEND_METHOD(ReflectionType, allowsNull)
30743074
/* For BC with iterable for named types */
30753075
static zend_string *zend_named_reflection_type_to_string(zend_type type) {
30763076
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(type)) {
3077-
zend_string *iterable = ZSTR_KNOWN(ZEND_STR_ITERABLE);
30783077
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_NULL) {
3079-
return zend_string_concat2("?", strlen("?"), ZSTR_VAL(iterable), ZSTR_LEN(iterable));
3078+
return ZSTR_INIT_LITERAL("?iterable", false);
30803079
}
3081-
return iterable;
3080+
return ZSTR_KNOWN(ZEND_STR_ITERABLE);
30823081
}
30833082
return zend_type_to_string(type);
30843083
}

0 commit comments

Comments
 (0)