Skip to content

Commit 7948954

Browse files
authored
Keep allocated memory when rhs fits
Use case: Appending to a String with pre-allocated memory (e.g. from `reserve()`)
1 parent d33b221 commit 7948954

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: cores/esp32/WString.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ String &String::copy(const char *cstr, unsigned int length) {
238238
#ifdef __GXX_EXPERIMENTAL_CXX0X__
239239
void String::move(String &rhs) {
240240
if (buffer()) {
241-
if (capacity() >= rhs.len() && rhs.len() && rhs.buffer()) {
242-
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
241+
if (capacity() >= rhs.len()) {
242+
// Use case: When 'reserve()' was called and the first
243+
// assignment/append is the return value of a function.
244+
if (rhs.len() && rhs.buffer()) {
245+
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
246+
}
243247
setLen(rhs.len());
244248
rhs.invalidate();
245249
return;

0 commit comments

Comments
 (0)