mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 03:16:37 +00:00
[web_server] Use zero-copy entity ID comparison in request handlers (#11644)
This commit is contained in:
@@ -48,8 +48,15 @@ struct UrlMatch {
|
||||
return domain && domain_len == strlen(str) && memcmp(domain, str, domain_len) == 0;
|
||||
}
|
||||
|
||||
bool id_equals(const std::string &str) const {
|
||||
return id && id_len == str.length() && memcmp(id, str.c_str(), id_len) == 0;
|
||||
bool id_equals_entity(EntityBase *entity) const {
|
||||
// Zero-copy comparison using StringRef
|
||||
StringRef static_ref = entity->get_object_id_ref_for_api_();
|
||||
if (!static_ref.empty()) {
|
||||
return id && id_len == static_ref.size() && memcmp(id, static_ref.c_str(), id_len) == 0;
|
||||
}
|
||||
// Fallback to allocation (rare)
|
||||
const auto &obj_id = entity->get_object_id();
|
||||
return id && id_len == obj_id.length() && memcmp(id, obj_id.c_str(), id_len) == 0;
|
||||
}
|
||||
|
||||
bool method_equals(const char *str) const {
|
||||
|
||||
Reference in New Issue
Block a user