2 ms·
clear() + push_str() to reuse the storage to assemble a new string. replace_range() to splice something in the middle. This may require the tail to be moved aro
by the8472 6y ago
clear() + push_str() to reuse the storage to assemble a new string.
replace_range() to splice something in the middle. This may require the tail to be moved around when lengths don't match.
Note that Strings are stored as utf8, so a substring with the same number of characters can still result in a different number of bytes and thus require memmoves.