From 4fb705a03dc73bfafbd81bd1ba23b30b0ec2a502 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 14 Apr 2020 17:17:38 +0200 Subject: Add zend_string_concat2 API --- Zend/zend_compile.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'Zend/zend_compile.c') 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; } -- cgit v1.2.1