[core] Use StringRef for get_comment and get_compilation_time to avoid allocations

This commit is contained in:
J. Nick Koston
2025-11-30 22:49:23 -06:00
parent b5a3c0be21
commit edf19b8dd4
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -360,7 +360,7 @@ void WiFiComponent::start() {
get_mac_address_pretty_into_buffer(mac_s));
this->last_connected_ = millis();
uint32_t hash = this->has_sta() ? fnv1_hash(App.get_compilation_time_ref()) : 88491487UL;
uint32_t hash = this->has_sta() ? fnv1_hash(App.get_compilation_time_ref().c_str()) : 88491487UL;
this->pref_ = global_preferences->make_preference<wifi::SavedWifiSettings>(hash, true);
#ifdef USE_WIFI_FAST_CONNECT
+3 -2
View File
@@ -15,7 +15,6 @@
#include <concepts>
#include "esphome/core/optional.h"
#include "esphome/core/string_ref.h"
#ifdef USE_ESP8266
#include <Esp.h>
@@ -48,6 +47,9 @@
namespace esphome {
// Forward declaration to avoid circular dependency with string_ref.h
class StringRef;
/// @name STL backports
///@{
@@ -378,7 +380,6 @@ uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc = 0, uint16_t p
/// Calculate a FNV-1 hash of \p str.
uint32_t fnv1_hash(const char *str);
inline uint32_t fnv1_hash(const std::string &str) { return fnv1_hash(str.c_str()); }
inline uint32_t fnv1_hash(const StringRef &str) { return fnv1_hash(str.c_str()); }
/// Return a random 32-bit unsigned integer.
uint32_t random_uint32();