[web_server] Use zero-copy entity ID comparison in request handlers (#11644)

This commit is contained in:
J. Nick Koston
2025-11-03 14:12:56 +13:00
committed by GitHub
parent 712421b82b
commit 4838eff382
3 changed files with 42 additions and 26 deletions
+9 -2
View File
@@ -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 {