Pass String by const reference [3.0] by dirkmueller · Pull Request #6583 · esp8266/Arduino · GitHub
Skip to content

Pass String by const reference [3.0]#6583

Merged
d-a-v merged 2 commits into
esp8266:masterfrom
dirkmueller:string_cleanups_30
Jul 10, 2020
Merged

Pass String by const reference [3.0]#6583
d-a-v merged 2 commits into
esp8266:masterfrom
dirkmueller:string_cleanups_30

Conversation

@dirkmueller

Copy link
Copy Markdown
Contributor

Passing String by value means a full copy-constructor/temporary
string creation which is slightly inefficient. Avoid that
by using const references.

@earlephilhower earlephilhower left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These are all basically private inside ESP8266WebServer, so I don't see any issue w/user classes even though they are virtual methods.

@devyte

devyte commented Oct 3, 2019

Copy link
Copy Markdown
Collaborator

@devyte devyte added this to the 3.0.0 milestone Oct 3, 2019
@earlephilhower

Copy link
Copy Markdown
Collaborator

Actually, @devyte, while what you say is possible, IMO they're virtual because we need to store a pointer to a generic RequestHandler in the webserver (i.e. internal considerations, not custom overloads).

Overloaded classes would suffer object slicing if we stored a pointer to the base class in the WebServer object, so these functions need to be virtual (even though I was able to rewrite the WebServer class to be a template w/o virtuals).

Passing String by value means a full copy-constructor/temporary
string creation which is slightly inefficient. Avoid that
by using const references.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This String copy can be handled differently in a further fixing commit.

@d-a-v d-a-v merged commit 83158af into esp8266:master Jul 10, 2020
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.

4 participants