Skip to content

WString explicit converters to reduce Flash size #6759

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

Conversation

s-hadinger
Copy link
Contributor

@s-hadinger 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));
str->startsWith(F("prefix"));
str->endsWith(F("suffix"));

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.

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@s-hadinger
Copy link
Contributor Author

@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
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Jason2866
Copy link
Contributor

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

@devyte devyte self-requested a review November 12, 2019 16:50
@earlephilhower earlephilhower merged commit 41d99ad into esp8266:master Nov 12, 2019
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.

5 participants