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

WString explicit converters to reduce Flash size #6759


Copy link

s-hadinger commented Nov 12, 2019

Tasmota uses a lot of String with constructs like below:

str->replace("aa", "bb);
str->replace(F("cc"), String(num));

Currently for any non String argument, the compiler silently instantiates a new Stringobject and deletes it after the call. This generates more than 1k of not very useful code.

This PR adds explicit methods to deal with common arguments const unsigned char * and const __FlashStringHelper *. It does not change the fact that a String object is created then deleted, it just reduces redundant code.

With this change, we see a 1k code size reduction with Tasmota.

Stephan Hadinger added 2 commits Nov 12, 2019
cores/esp8266/WString.h Outdated Show resolved Hide resolved
d-a-v approved these changes Nov 12, 2019
Copy link

d-a-v left a comment

This PR adds explicit code where gcc uses implicit code.
If there is less generated code, it means that the added methods are not inlined by the compiler.
approving (modulo the missing const done, thanks)


This comment has been minimized.

Copy link
Contributor Author

s-hadinger commented Nov 12, 2019

@d-a-v Indeed, I added the missing const for startsWith() and endsWith(). As you mentioned, the added methods should not be inlined, that's the point.

Copy link

earlephilhower left a comment

LGTM, thanks!


This comment has been minimized.

Copy link

Jason2866 commented Nov 12, 2019

Could you add to milestone 2.6.1 or better merge before? :-)

@devyte devyte self-requested a review Nov 12, 2019
devyte approved these changes Nov 12, 2019
@earlephilhower earlephilhower merged commit 41d99ad into esp8266:master Nov 12, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
5 participants
You can’t perform that action at this time.