mirror of
https://github.com/esphome/esphome.git
synced 2026-10-05 18:41:32 +00:00
[text] Store pattern as const char* to reduce memory usage
This commit is contained in:
@@ -16,7 +16,7 @@ void TemplateText::setup() {
|
|||||||
uint32_t key = this->get_preference_hash();
|
uint32_t key = this->get_preference_hash();
|
||||||
key += this->traits.get_min_length() << 2;
|
key += this->traits.get_min_length() << 2;
|
||||||
key += this->traits.get_max_length() << 4;
|
key += this->traits.get_max_length() << 4;
|
||||||
key += fnv1_hash(this->traits.get_pattern_ref().c_str()) << 6;
|
key += fnv1_hash(this->traits.get_pattern_c_str()) << 6;
|
||||||
this->pref_->setup(key, value);
|
this->pref_->setup(key, value);
|
||||||
}
|
}
|
||||||
if (!value.empty())
|
if (!value.empty())
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class TextTraits {
|
|||||||
// Set/get the pattern.
|
// Set/get the pattern.
|
||||||
void set_pattern(const char *pattern) { this->pattern_ = pattern; }
|
void set_pattern(const char *pattern) { this->pattern_ = pattern; }
|
||||||
std::string get_pattern() const { return std::string(this->pattern_); }
|
std::string get_pattern() const { return std::string(this->pattern_); }
|
||||||
|
const char *get_pattern_c_str() const { return this->pattern_; }
|
||||||
StringRef get_pattern_ref() const { return StringRef(this->pattern_); }
|
StringRef get_pattern_ref() const { return StringRef(this->pattern_); }
|
||||||
|
|
||||||
// Set/get the frontend mode.
|
// Set/get the frontend mode.
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
|
|||||||
stream.print(R"(" maxlength=")");
|
stream.print(R"(" maxlength=")");
|
||||||
stream.print(text->traits.get_max_length());
|
stream.print(text->traits.get_max_length());
|
||||||
stream.print(R"(" pattern=")");
|
stream.print(R"(" pattern=")");
|
||||||
stream.print(text->traits.get_pattern_ref().c_str());
|
stream.print(text->traits.get_pattern_c_str());
|
||||||
stream.print(R"(" value=")");
|
stream.print(R"(" value=")");
|
||||||
stream.print(text->state.c_str());
|
stream.print(text->state.c_str());
|
||||||
stream.print(R"("/>)");
|
stream.print(R"("/>)");
|
||||||
|
|||||||
Reference in New Issue
Block a user