mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
[core] Flatten single-callsite vector realloc functions
On ESP8266 (GCC 10.3), std::vector::push_back/emplace_back emit separate _M_realloc_insert functions even when called from only one site. Adding __attribute__((flatten)) inlines the realloc path, saving the out-of-line function overhead. Changes: - wifi: Move set_sta_priority from header to .cpp (eliminates duplicate instantiation at 2 call sites) and add flatten - web_server_base: Flatten add_handler (single push_back site) - api: Flatten accept_new_connections_ (single emplace_back site) Saves 160 bytes of flash on ESP8266.
This commit is contained in:
@@ -195,7 +195,7 @@ void APIServer::remove_client_(size_t client_index) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIServer::accept_new_connections_() {
|
void __attribute__((flatten)) APIServer::accept_new_connections_() {
|
||||||
while (true) {
|
while (true) {
|
||||||
struct sockaddr_storage source_addr;
|
struct sockaddr_storage source_addr;
|
||||||
socklen_t addr_len = sizeof(source_addr);
|
socklen_t addr_len = sizeof(source_addr);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ static const char *const TAG = "web_server_base";
|
|||||||
|
|
||||||
WebServerBase *global_web_server_base = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
WebServerBase *global_web_server_base = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
void WebServerBase::add_handler(AsyncWebHandler *handler) {
|
void __attribute__((flatten)) WebServerBase::add_handler(AsyncWebHandler *handler) {
|
||||||
// remove all handlers
|
// remove all handlers
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER_AUTH
|
#ifdef USE_WEBSERVER_AUTH
|
||||||
|
|||||||
@@ -487,6 +487,19 @@ bool WiFiComponent::matches_configured_network_(const char *ssid, const uint8_t
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __attribute__((flatten)) WiFiComponent::set_sta_priority(const bssid_t bssid, int8_t priority) {
|
||||||
|
for (auto &it : this->sta_priorities_) {
|
||||||
|
if (it.bssid == bssid) {
|
||||||
|
it.priority = priority;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->sta_priorities_.push_back(WiFiSTAPriority{
|
||||||
|
.bssid = bssid,
|
||||||
|
.priority = priority,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void WiFiComponent::log_discarded_scan_result_(const char *ssid, const uint8_t *bssid, int8_t rssi, uint8_t channel) {
|
void WiFiComponent::log_discarded_scan_result_(const char *ssid, const uint8_t *bssid, int8_t rssi, uint8_t channel) {
|
||||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||||
// Skip logging during roaming scans to avoid log buffer overflow
|
// Skip logging during roaming scans to avoid log buffer overflow
|
||||||
|
|||||||
@@ -488,18 +488,7 @@ class WiFiComponent : public Component {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void set_sta_priority(const bssid_t bssid, int8_t priority) {
|
void set_sta_priority(const bssid_t bssid, int8_t priority);
|
||||||
for (auto &it : this->sta_priorities_) {
|
|
||||||
if (it.bssid == bssid) {
|
|
||||||
it.priority = priority;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->sta_priorities_.push_back(WiFiSTAPriority{
|
|
||||||
.bssid = bssid,
|
|
||||||
.priority = priority,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
network::IPAddresses wifi_sta_ip_addresses();
|
network::IPAddresses wifi_sta_ip_addresses();
|
||||||
// Remove before 2026.9.0
|
// Remove before 2026.9.0
|
||||||
|
|||||||
Reference in New Issue
Block a user