Skip to content

Commit 1aeea12

Browse files
earlephilhowerdevyte
authored andcommitted
Speed up empty String creation slightly (#6573)
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().
1 parent 1d26b28 commit 1aeea12

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: cores/esp8266/WString.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class String {
5353
// if the initial value is null or invalid, or if memory allocation
5454
// fails, the string will be marked as invalid (i.e. "if (s)" will
5555
// be false).
56-
String(const char *cstr = "");
56+
String(const char *cstr = nullptr);
5757
String(const String &str);
5858
String(const __FlashStringHelper *str);
5959
#ifdef __GXX_EXPERIMENTAL_CXX0X__

0 commit comments

Comments
 (0)