mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
use existing capacity in Str.concat if possible
This commit is contained in:
parent
52605fcca9
commit
36b42fb62b
1 changed files with 7 additions and 0 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue