mirror of
https://github.com/esphome/esphome.git
synced 2026-09-02 19:16:06 +00:00
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.
36 lines
934 B
C++
36 lines
934 B
C++
#include "web_server_base.h"
|
|
#ifdef USE_NETWORK
|
|
#include "esphome/core/application.h"
|
|
#include "esphome/core/helpers.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace web_server_base {
|
|
|
|
static const char *const TAG = "web_server_base";
|
|
|
|
WebServerBase *global_web_server_base = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
|
|
|
void __attribute__((flatten)) WebServerBase::add_handler(AsyncWebHandler *handler) {
|
|
// remove all handlers
|
|
|
|
#ifdef USE_WEBSERVER_AUTH
|
|
if (!credentials_.username.empty()) {
|
|
handler = new internal::AuthMiddlewareHandler(handler, &credentials_);
|
|
}
|
|
#endif
|
|
this->handlers_.push_back(handler);
|
|
if (this->server_ != nullptr) {
|
|
this->server_->addHandler(handler);
|
|
}
|
|
}
|
|
|
|
float WebServerBase::get_setup_priority() const {
|
|
// Before WiFi (captive portal)
|
|
return setup_priority::WIFI + 2.0f;
|
|
}
|
|
|
|
} // namespace web_server_base
|
|
} // namespace esphome
|
|
#endif
|