1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 02:40:56 +01:00

HttpRequestComponent::get_string - avoid copy (#2988)

This commit is contained in:
Roi Tagar 2022-02-17 06:03:54 +02:00 committed by GitHub
parent 36ddd9dd69
commit 958ad0d750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,10 +120,16 @@ void HttpRequestComponent::close() {
}
const char *HttpRequestComponent::get_string() {
// The static variable is here because HTTPClient::getString() returns a String on ESP32, and we need something to
// to keep a buffer alive.
static std::string str;
str = this->client_.getString().c_str();
#if defined(ESP32)
// The static variable is here because HTTPClient::getString() returns a String on ESP32,
// and we need something to keep a buffer alive.
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();
}