summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-04-14 17:17:38 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-04-14 17:18:05 +0200
commit4fb705a03dc73bfafbd81bd1ba23b30b0ec2a502 (patch)
tree4beeeb15cfc1f13918c0ca560c9346320795ad12 /Zend/zend_compile.c
parent489a51bff077671e77f29b01f2575c54c1ef452b (diff)
downloadphp-git-4fb705a03dc73bfafbd81bd1ba23b30b0ec2a502.tar.gz
Add zend_string_concat2 API
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r--Zend/zend_compile.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 1c7f5f1073..953bf6dfd5 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1161,12 +1161,8 @@ static zend_string *add_type_string(zend_string *type, zend_string *new_type) {
return zend_string_copy(new_type);
}
- // TODO: Switch to smart_str?
- result = zend_string_alloc(ZSTR_LEN(type) + ZSTR_LEN(new_type) + 1, 0);
- memcpy(ZSTR_VAL(result), ZSTR_VAL(type), ZSTR_LEN(type));
- ZSTR_VAL(result)[ZSTR_LEN(type)] = '|';
- memcpy(ZSTR_VAL(result) + ZSTR_LEN(type) + 1, ZSTR_VAL(new_type), ZSTR_LEN(new_type));
- ZSTR_VAL(result)[ZSTR_LEN(type) + ZSTR_LEN(new_type) + 1] = '\0';
+ result = zend_string_concat3(
+ ZSTR_VAL(type), ZSTR_LEN(type), "|", 1, ZSTR_VAL(new_type), ZSTR_LEN(new_type));
zend_string_release(type);
return result;
}
@@ -1243,10 +1239,7 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
if (type_mask & MAY_BE_NULL) {
zend_bool is_union = !str || memchr(ZSTR_VAL(str), '|', ZSTR_LEN(str)) != NULL;
if (!is_union) {
- zend_string *nullable_str = zend_string_alloc(ZSTR_LEN(str) + 1, 0);
- ZSTR_VAL(nullable_str)[0] = '?';
- memcpy(ZSTR_VAL(nullable_str) + 1, ZSTR_VAL(str), ZSTR_LEN(str));
- ZSTR_VAL(nullable_str)[ZSTR_LEN(nullable_str)] = '\0';
+ zend_string *nullable_str = zend_string_concat2("?", 1, ZSTR_VAL(str), ZSTR_LEN(str));
zend_string_release(str);
return nullable_str;
}