mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
[core] Use StringRef for get_comment and get_compilation_time to avoid allocations
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user