use existing capacity in Str.concat if possible

This commit is contained in:
Folkert 2022-07-06 17:58:48 +02:00
parent 52605fcca9
commit 36b42fb62b
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C

View File

@ -1419,6 +1419,13 @@ fn strConcat(arg1: RocStr, arg2: RocStr) RocStr {
const element_width = 1;
if (arg1.isUnique() and (arg1.capacity() - arg1.len()) >= arg2.len()) {
const destination = arg1.asU8ptr() + arg1.len();
@memcpy(destination, arg2.asU8ptr(), arg2.len());
return arg1;
}
if (!arg1.isSmallStr() and arg1.isUnique()) {
if (arg1.str_bytes) |source_ptr| {
const new_source = utils.unsafeReallocate(