Skip to content

Commit 80944fe

Browse files
authored
Simplify calls to String::copy
A lot of the same checks were done before calling `copy()` which should be done in the `copy()` function itself.
1 parent 6fcaf69 commit 80944fe

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

Diff for: cores/esp32/WString.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
226226
/*********************************************/
227227

228228
String &String::copy(const char *cstr, unsigned int length) {
229-
if (!reserve(length)) {
229+
if (cstr == nullptr || !reserve(length)) {
230230
invalidate();
231231
return *this;
232232
}
@@ -270,12 +270,7 @@ String &String::operator=(const String &rhs) {
270270
if (this == &rhs) {
271271
return *this;
272272
}
273-
if (rhs.buffer()) {
274-
copy(rhs.buffer(), rhs.len());
275-
} else {
276-
invalidate();
277-
}
278-
return *this;
273+
return copy(rhs.buffer(), rhs.len());
279274
}
280275

281276
#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -295,12 +290,7 @@ String &String::operator=(StringSumHelper &&rval) {
295290
#endif
296291

297292
String &String::operator=(const char *cstr) {
298-
if (cstr) {
299-
copy(cstr, strlen(cstr));
300-
} else {
301-
invalidate();
302-
}
303-
return *this;
293+
return copy(cstr, strlen(cstr));
304294
}
305295

306296
/*********************************************/

0 commit comments

Comments
 (0)