mirror of
https://github.com/esphome/esphome.git
synced 2026-05-22 10:25:46 +08:00
Optimize web_server UrlMatch to avoid heap allocations (#9263)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -40,10 +40,28 @@ namespace web_server {
|
||||
|
||||
/// Internal helper struct that is used to parse incoming URLs
|
||||
struct UrlMatch {
|
||||
std::string domain; ///< The domain of the component, for example "sensor"
|
||||
std::string id; ///< The id of the device that's being accessed, for example "living_room_fan"
|
||||
std::string method; ///< The method that's being called, for example "turn_on"
|
||||
const char *domain; ///< Pointer to domain within URL, for example "sensor"
|
||||
const char *id; ///< Pointer to id within URL, for example "living_room_fan"
|
||||
const char *method; ///< Pointer to method within URL, for example "turn_on"
|
||||
uint8_t domain_len; ///< Length of domain string
|
||||
uint8_t id_len; ///< Length of id string
|
||||
uint8_t method_len; ///< Length of method string
|
||||
bool valid; ///< Whether this match is valid
|
||||
|
||||
// Helper methods for string comparisons
|
||||
bool domain_equals(const char *str) const {
|
||||
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 method_equals(const char *str) const {
|
||||
return method && method_len == strlen(str) && memcmp(method, str, method_len) == 0;
|
||||
}
|
||||
|
||||
bool method_empty() const { return method_len == 0; }
|
||||
};
|
||||
|
||||
#ifdef USE_WEBSERVER_SORTING
|
||||
|
||||
Reference in New Issue
Block a user