1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 06:45:48 +00:00

[network] Optimize get_use_address() to return const reference instead of a copy (#11218)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
J. Nick Koston
2025-10-13 17:54:33 -10:00
committed by GitHub
parent 9eef281895
commit 4c688a4b00
6 changed files with 20 additions and 27 deletions

View File

@@ -265,14 +265,9 @@ network::IPAddress WiFiComponent::get_dns_address(int num) {
return this->wifi_dns_ip_(num);
return {};
}
std::string WiFiComponent::get_use_address() const {
if (this->use_address_.empty()) {
// ".local" suffix length for mDNS hostnames
constexpr size_t mdns_local_suffix_len = 5;
return make_name_with_suffix(App.get_name(), '.', "local", mdns_local_suffix_len);
}
return this->use_address_;
}
// set_use_address() is guaranteed to be called during component setup by Python code generation,
// so use_address_ will always be valid when get_use_address() is called - no fallback needed.
const std::string &WiFiComponent::get_use_address() const { return this->use_address_; }
void WiFiComponent::set_use_address(const std::string &use_address) { this->use_address_ = use_address; }
#ifdef USE_WIFI_AP