mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
HttpRequestComponent::get_string - avoid copy (#2988)
This commit is contained in:
parent
36ddd9dd69
commit
958ad0d750
1 changed files with 10 additions and 4 deletions
|
@ -120,10 +120,16 @@ void HttpRequestComponent::close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *HttpRequestComponent::get_string() {
|
const char *HttpRequestComponent::get_string() {
|
||||||
// The static variable is here because HTTPClient::getString() returns a String on ESP32, and we need something to
|
#if defined(ESP32)
|
||||||
// to keep a buffer alive.
|
// The static variable is here because HTTPClient::getString() returns a String on ESP32,
|
||||||
static std::string str;
|
// and we need something to keep a buffer alive.
|
||||||
str = this->client_.getString().c_str();
|
static String str;
|
||||||
|
#else
|
||||||
|
// However on ESP8266, HTTPClient::getString() returns a String& to a member variable.
|
||||||
|
// Leaving this the default so that any new platform either doesn't copy, or encounters a compilation error.
|
||||||
|
auto &
|
||||||
|
#endif
|
||||||
|
str = this->client_.getString();
|
||||||
return str.c_str();
|
return str.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue