1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-15 01:32:19 +01:00

Eliminate API component guard variable to save 8 bytes RAM (#9341)

This commit is contained in:
J. Nick Koston
2025-07-05 23:34:55 -05:00
committed by GitHub
parent 20ba035e3b
commit 0bc18a8281
2 changed files with 18 additions and 2 deletions

View File

@@ -25,6 +25,11 @@ struct SavedNoisePsk {
} PACKED; // NOLINT
#endif
#ifndef USE_API_YAML_SERVICES
// Forward declaration of helper function
const std::vector<UserServiceDescriptor *> &get_empty_user_services_instance();
#endif
class APIServer : public Component, public Controller {
public:
APIServer();
@@ -151,8 +156,11 @@ class APIServer : public Component, public Controller {
#ifdef USE_API_YAML_SERVICES
return this->user_services_;
#else
static const std::vector<UserServiceDescriptor *> EMPTY;
return this->user_services_ ? *this->user_services_ : EMPTY;
if (this->user_services_) {
return *this->user_services_;
}
// Return reference to global empty instance (no guard needed)
return get_empty_user_services_instance();
#endif
}