Skip to content

Commit

Permalink
Speed up empty String creation slightly (#6573)
Browse files Browse the repository at this point in the history
As @DirkMuller found out in #6568, there is a difference in code
executed between `String str(nullptr)` and `String str("")`, but in the
end the actual object is identical.  It's a few bytes of code, but every
little bit counts.

Update the default `String()` constructor to use `nullptr` and not `""`.
This will remove a constant literal load and the execution of the
String::copy method and strlen().
  • Loading branch information
earlephilhower authored and devyte committed Oct 1, 2019
1 parent 1d26b28 commit 1aeea12
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class String {
// if the initial value is null or invalid, or if memory allocation
// fails, the string will be marked as invalid (i.e. "if (s)" will
// be false).
String(const char *cstr = "");
String(const char *cstr = nullptr);
String(const String &str);
String(const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
Expand Down

0 comments on commit 1aeea12

Please sign in to comment.