[http_request] Replace std::map with std::vector<std::pair> 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 <map> include.
This commit is contained in:
J. Nick Koston
2026-02-16 19:05:44 -06:00
parent 2b21c0a2b2
commit 87e998f455

View File

@@ -1,7 +1,6 @@
#pragma once
#include <list>
#include <map>
#include <memory>
#include <set>
#include <utility>
@@ -401,12 +400,12 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
#endif
void add_request_header(const char *key, TemplatableValue<const char *, Ts...> 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<std::string, Ts...> value) { this->json_.insert({key, value}); }
void add_json(const char *key, TemplatableValue<std::string, Ts...> value) { this->json_.push_back({key, value}); }
void set_json(std::function<void(Ts..., JsonObject)> json_func) { this->json_func_ = json_func; }
@@ -508,9 +507,9 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
}
void encode_json_func_(Ts... x, JsonObject root) { this->json_func_(x..., root); }
HttpRequestComponent *parent_;
std::map<const char *, TemplatableValue<const char *, Ts...>> request_headers_{};
std::vector<std::pair<const char *, TemplatableValue<const char *, Ts...>>> request_headers_{};
std::vector<std::string> collect_headers_{"content-type", "content-length"};
std::map<const char *, TemplatableValue<std::string, Ts...>> json_{};
std::vector<std::pair<const char *, TemplatableValue<std::string, Ts...>>> json_{};
std::function<void(Ts..., JsonObject)> json_func_{nullptr};
#ifdef USE_HTTP_REQUEST_RESPONSE
Trigger<std::shared_ptr<HttpContainer>, std::string &, Ts...> success_trigger_with_response_;