1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 16:51:52 +00:00

[text] Store pattern as const char* to reduce memory usage

This commit is contained in:
J. Nick Koston
2025-12-06 23:55:15 -06:00
parent 789faca7c4
commit e63673f5ef
3 changed files with 3 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ void TemplateText::setup() {
uint32_t key = this->get_preference_hash();
key += this->traits.get_min_length() << 2;
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);
}
if (!value.empty())

View File

@@ -23,6 +23,7 @@ class TextTraits {
// Set/get the pattern.
void set_pattern(const char *pattern) { this->pattern_ = 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_); }
// Set/get the frontend mode.

View File

@@ -142,7 +142,7 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
stream.print(R"(" maxlength=")");
stream.print(text->traits.get_max_length());
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(text->state.c_str());
stream.print(R"("/>)");