Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cores/esp32/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,18 @@ String &String::copy(const char *cstr, unsigned int length) {
void String::move(String &rhs) {
if (buffer()) {
if (capacity() >= rhs.len()) {
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
// Use case: When 'reserve()' was called and the first
// assignment/append is the return value of a function.
if (rhs.len() && rhs.buffer()) {
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
}
setLen(rhs.len());
rhs.invalidate();
return;
} else {
if (!isSSO()) {
free(wbuffer());
setBuffer(nullptr);
}
}
if (!isSSO()) {
free(wbuffer());
setBuffer(nullptr);
}
}
if (rhs.isSSO()) {
Expand All @@ -259,10 +262,7 @@ void String::move(String &rhs) {
}
setCapacity(rhs.capacity());
setLen(rhs.len());
rhs.setSSO(false);
rhs.setCapacity(0);
rhs.setBuffer(nullptr);
rhs.setLen(0);
rhs.init();
}
#endif

Expand Down
Loading