Skip to content

Commit 0de7d81

Browse files
committed
Permit moving some strings in
This reduces the number of allocations and copies required.
1 parent 585c00f commit 0de7d81

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/ESPAsyncWebServer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class AsyncWebParameter {
9090

9191
public:
9292

93-
AsyncWebParameter(const String& name, const String& value, bool form=false, bool file=false, size_t size=0): _name(name), _value(value), _size(size), _isForm(form), _isFile(file){}
93+
AsyncWebParameter(String name, String value, bool form=false, bool file=false, size_t size=0): _name(std::move(name)), _value(std::move(value)), _size(size), _isForm(form), _isFile(file){}
9494
const String& name() const { return _name; }
9595
const String& value() const { return _value; }
9696
size_t size() const { return _size; }
@@ -108,7 +108,7 @@ class AsyncWebHeader {
108108
String _value;
109109

110110
public:
111-
AsyncWebHeader(const String& name, const String& value): _name(name), _value(value){}
111+
AsyncWebHeader(String name, String value): _name(std::move(name)), _value(std::move(value)){}
112112
AsyncWebHeader(const String& data): _name(), _value(){
113113
if(!data) return;
114114
int index = data.indexOf(':');
@@ -231,10 +231,10 @@ class AsyncWebServerRequest {
231231
void setHandler(AsyncWebHandler *handler){ _handler = handler; }
232232
void addInterestingHeader(const String& name);
233233

234-
void redirect(const String& url);
234+
void redirect(String url);
235235

236236
void send(AsyncWebServerResponse *response);
237-
void send(int code, const String& contentType=String(), const String& content=String());
237+
void send(int code, String contentType=String(), String content=String());
238238
void send(FS &fs, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
239239
void send(File content, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
240240
void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback=nullptr);
@@ -243,7 +243,7 @@ class AsyncWebServerRequest {
243243
void send_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
244244
void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
245245

246-
AsyncWebServerResponse *beginResponse(int code, const String& contentType=String(), const String& content=String());
246+
AsyncWebServerResponse *beginResponse(int code, String contentType=String(), String content=String());
247247
AsyncWebServerResponse *beginResponse(FS &fs, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
248248
AsyncWebServerResponse *beginResponse(File content, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
249249
AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback=nullptr);

src/WebRequest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ void AsyncWebServerRequest::send(AsyncWebServerResponse *response){
738738
}
739739
}
740740

741-
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, const String& content){
742-
return new AsyncBasicResponse(code, contentType, content);
741+
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, String contentType, String content){
742+
return new AsyncBasicResponse(code, std::move(contentType), std::move(content));
743743
}
744744

745745
AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(FS &fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback){
@@ -780,8 +780,8 @@ AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const
780780
return beginResponse_P(code, contentType, (const uint8_t *)content, strlen_P(content), callback);
781781
}
782782

783-
void AsyncWebServerRequest::send(int code, const String& contentType, const String& content){
784-
send(beginResponse(code, contentType, content));
783+
void AsyncWebServerRequest::send(int code, String contentType, String content){
784+
send(beginResponse(code, std::move(contentType), std::move(content)));
785785
}
786786

787787
void AsyncWebServerRequest::send(FS &fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback){
@@ -816,9 +816,9 @@ void AsyncWebServerRequest::send_P(int code, const String& contentType, PGM_P co
816816
send(beginResponse_P(code, contentType, content, callback));
817817
}
818818

819-
void AsyncWebServerRequest::redirect(const String& url){
819+
void AsyncWebServerRequest::redirect(String url){
820820
AsyncWebServerResponse * response = beginResponse(302);
821-
response->addHeader("Location",url);
821+
response->addHeader(F("Location"), std::move(url));
822822
send(response);
823823
}
824824

src/WebResponseImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AsyncBasicResponse: public AsyncWebServerResponse {
3333
private:
3434
String _content;
3535
public:
36-
AsyncBasicResponse(int code, const String& contentType=String(), const String& content=String());
36+
AsyncBasicResponse(int code, String contentType=String(), String content=String());
3737
void _respond(AsyncWebServerRequest *request);
3838
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
3939
bool _sourceValid() const { return true; }

src/WebResponses.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ size_t AsyncWebServerResponse::_ack(AsyncWebServerRequest *request, size_t len,
196196
/*
197197
* String/Code Response
198198
* */
199-
AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, const String& content){
199+
AsyncBasicResponse::AsyncBasicResponse(int code, String contentType, String content){
200200
_code = code;
201-
_content = content;
202-
_contentType = contentType;
201+
_content = std::move(content);
202+
_contentType = std::move(contentType);
203203
if(_content.length()){
204204
_contentLength = _content.length();
205205
if(!_contentType.length())

0 commit comments

Comments
 (0)