Pass String by const reference [3.0]#6583
Conversation
81a3e2f to
28c745c
Compare
earlephilhower
left a comment
There was a problem hiding this comment.
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.
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.