Skip to content

Commit f1fa4c5

Browse files
committed
ESP8266WebServer: reduce amount of string copying
1 parent 1c8b52b commit f1fa4c5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void ESP8266WebServer::handleClient()
115115
_handleRequest();
116116
}
117117

118-
void ESP8266WebServer::sendHeader(String name, String value, bool first) {
118+
void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) {
119119
String headerLine = name;
120120
headerLine += ": ";
121121
headerLine += value;
@@ -129,7 +129,7 @@ void ESP8266WebServer::sendHeader(String name, String value, bool first) {
129129
}
130130
}
131131

132-
void ESP8266WebServer::send(int code, const char* content_type, String content) {
132+
void ESP8266WebServer::send(int code, const char* content_type, const String& content) {
133133
String response = "HTTP/1.1 ";
134134
response += String(code);
135135
response += " ";
@@ -155,15 +155,15 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
155155
sendContent(response);
156156
}
157157

158-
void ESP8266WebServer::send(int code, char* content_type, String content) {
158+
void ESP8266WebServer::send(int code, char* content_type, const String& content) {
159159
send(code, (const char*)content_type, content);
160160
}
161161

162-
void ESP8266WebServer::send(int code, String content_type, String content) {
162+
void ESP8266WebServer::send(int code, const String& content_type, const String& content) {
163163
send(code, (const char*)content_type.c_str(), content);
164164
}
165165

166-
void ESP8266WebServer::sendContent(String content) {
166+
void ESP8266WebServer::sendContent(const String& content) {
167167
size_t size_to_send = content.length();
168168
size_t size_sent = 0;
169169
while(size_to_send) {

hardware/esp8266com/esp8266/libraries/ESP8266WebServer/src/ESP8266WebServer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ class ESP8266WebServer
7777
// code - HTTP response code, can be 200 or 404
7878
// content_type - HTTP content type, like "text/plain" or "image/png"
7979
// content - actual content body
80-
void send(int code, const char* content_type = NULL, String content = String(""));
81-
void send(int code, char* content_type, String content);
82-
void send(int code, String content_type, String content);
80+
void send(int code, const char* content_type = NULL, const String& content = String(""));
81+
void send(int code, char* content_type, const String& content);
82+
void send(int code, const String& content_type, const String& content);
8383

8484
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
85-
void sendHeader(String name, String value, bool first = false);
86-
void sendContent(String content);
85+
void sendHeader(const String& name, const String& value, bool first = false);
86+
void sendContent(const String& content);
8787

88-
template<typename T> size_t streamFile(T &file, String contentType){
88+
template<typename T> size_t streamFile(T &file, const String& contentType){
8989
setContentLength(file.size());
9090
if (String(file.name()).endsWith(".gz") &&
9191
contentType != "application/x-gzip" &&

0 commit comments

Comments
 (0)