Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up empty String creation slightly #6573

Merged
merged 4 commits into from
Oct 1, 2019

Conversation

earlephilhower
Copy link
Collaborator

@earlephilhower earlephilhower commented Sep 30, 2019

As @dirkmueller (sorry bout typo!) 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().

earlephilhower and others added 3 commits September 30, 2019 15:03
As @DirkMuller found out in esp8266#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().
@devyte devyte merged commit 1aeea12 into esp8266:master Oct 1, 2019
earlephilhower added a commit that referenced this pull request Oct 1, 2019
earlephilhower added a commit to earlephilhower/Arduino that referenced this pull request Oct 1, 2019
PR esp8266#6573 introduced a corner case where a blind String() without any
initialization was in an in invalid state because the buffer and len
would not be updated properly.  Concatenating to the empty string could
cause a failure.

Now, set the default state in ::init() to SSO (which is what happened
before when we were using String(char *s="")) and fix the crash.
earlephilhower added a commit to earlephilhower/Arduino that referenced this pull request Oct 1, 2019
PR esp8266#6573 introduced a corner case where a blind String() without any
initialization was in an in invalid state because the buffer and len
would not be updated properly.  Concatenating to the empty string could
cause a failure.

Now, set the default state in ::init() to SSO (which is what happened
before when we were using String(char *s="")) and fix the crash.
earlephilhower added a commit that referenced this pull request Oct 1, 2019
* Replace ASM block w/C marco for PSTR

GAS doesn't support the C language idiom of catenating two strings
together with quotes (i.e. "x" "y" === "xy").

Specify the section attribute fully in the section attribute, instead,
to allow this.

* Fix WString optimization

PR #6573 introduced a corner case where a blind String() without any
initialization was in an in invalid state because the buffer and len
would not be updated properly.  Concatenating to the empty string could
cause a failure.

Now, set the default state in ::init() to SSO (which is what happened
before when we were using String(char *s="")) and fix the crash.
@earlephilhower earlephilhower deleted the string-to-null branch November 18, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants