From 87e998f455bf6cf88fad0257bf42ab8d2124daba Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Feb 2026 19:05:44 -0600 Subject: [PATCH] [http_request] Replace std::map with std::vector in action template request_headers_ and json_ are populated at config time via add_request_header()/add_json() and only iterated linearly at runtime. std::map's red-black tree is unnecessary overhead for these small collections. Drop the include. --- esphome/components/http_request/http_request.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/http_request/http_request.h b/esphome/components/http_request/http_request.h index cbf6273b51..17aeeba7d0 100644 --- a/esphome/components/http_request/http_request.h +++ b/esphome/components/http_request/http_request.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -401,12 +400,12 @@ template class HttpRequestSendAction : public Action { #endif void add_request_header(const char *key, TemplatableValue value) { - this->request_headers_.insert({key, value}); + this->request_headers_.push_back({key, value}); } void add_collect_header(const char *value) { this->collect_headers_.push_back(value); } - void add_json(const char *key, TemplatableValue value) { this->json_.insert({key, value}); } + void add_json(const char *key, TemplatableValue value) { this->json_.push_back({key, value}); } void set_json(std::function json_func) { this->json_func_ = json_func; } @@ -508,9 +507,9 @@ template class HttpRequestSendAction : public Action { } void encode_json_func_(Ts... x, JsonObject root) { this->json_func_(x..., root); } HttpRequestComponent *parent_; - std::map> request_headers_{}; + std::vector>> request_headers_{}; std::vector collect_headers_{"content-type", "content-length"}; - std::map> json_{}; + std::vector>> json_{}; std::function json_func_{nullptr}; #ifdef USE_HTTP_REQUEST_RESPONSE Trigger, std::string &, Ts...> success_trigger_with_response_;