-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Pass String by const reference [3.0] #6583
Conversation
81a3e2f
to
28c745c
Compare
There was a problem hiding this comment.
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.
The reason they're virtual is to allow a user to implement his own RequestHandler objects. |
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.
28c745c
to
561b7f4
Compare
bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) override { | ||
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& __requestUri) override { | ||
String requestUri(__requestUri); | ||
|
There was a problem hiding this comment.
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.
Passing String by value means a full copy-constructor/temporary
string creation which is slightly inefficient. Avoid that
by using const references.