[api] Inline APIServer::is_connected() for common no-arg path

The is_connected() method is called on every BLE advertisement
in the bluetooth_proxy hot path, but was forced out-of-line by
the state_subscription_only parameter added in #11906.

The default path (no argument) is just `!clients_.empty()` — a
simple pointer comparison. Split into:
- is_connected(): inline in header (common fast path)
- is_connected_with_state_subscription(): out-of-line (rare path)

No callers pass true directly; only APIConnectedCondition uses
the state_subscription_only template value, updated accordingly.
This commit is contained in:
J. Nick Koston
2026-03-06 12:53:41 -10:00
parent 6e3bc7b1dd
commit f723deca18
2 changed files with 7 additions and 7 deletions
+1 -5
View File
@@ -582,11 +582,7 @@ void APIServer::request_time() {
}
#endif
bool APIServer::is_connected(bool state_subscription_only) const {
if (!state_subscription_only) {
return !this->clients_.empty();
}
bool APIServer::is_connected_with_state_subscription() const {
for (const auto &client : this->clients_) {
if (client->flags_.state_subscription) {
return true;
+6 -2
View File
@@ -185,7 +185,8 @@ class APIServer : public Component,
void send_infrared_rf_receive_event(uint32_t device_id, uint32_t key, const std::vector<int32_t> *timings);
#endif
bool is_connected(bool state_subscription_only = false) const;
bool is_connected() const { return !this->clients_.empty(); }
bool is_connected_with_state_subscription() const;
#ifdef USE_API_HOMEASSISTANT_STATES
struct HomeAssistantStateSubscription {
@@ -323,7 +324,10 @@ template<typename... Ts> class APIConnectedCondition : public Condition<Ts...> {
TEMPLATABLE_VALUE(bool, state_subscription_only)
public:
bool check(const Ts &...x) override {
return global_api_server->is_connected(this->state_subscription_only_.value(x...));
if (this->state_subscription_only_.value(x...)) {
return global_api_server->is_connected_with_state_subscription();
}
return global_api_server->is_connected();
}
};