From 124b3075eb594f74a9b949f9af84044f3cb06bbc Mon Sep 17 00:00:00 2001 From: Adi Suissa-Peleg Date: Wed, 13 Nov 2024 22:25:16 +0000 Subject: [PATCH] router: pre-reserve header_parser vectors by their sizes Signed-off-by: Adi Suissa-Peleg --- source/common/router/header_parser.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/common/router/header_parser.cc b/source/common/router/header_parser.cc index f7feb18a632e..a3f75e621223 100644 --- a/source/common/router/header_parser.cc +++ b/source/common/router/header_parser.cc @@ -87,6 +87,7 @@ HeadersToAddEntry::HeadersToAddEntry(const HeaderValue& header_value, absl::StatusOr HeaderParser::configure(const Protobuf::RepeatedPtrField& headers_to_add) { HeaderParserPtr header_parser(new HeaderParser()); + header_parser->headers_to_add_.reserve(headers_to_add.size()); for (const auto& header_value_option : headers_to_add) { auto entry_or_error = HeadersToAddEntry::create(header_value_option); RETURN_IF_NOT_OK_REF(entry_or_error.status()); @@ -103,6 +104,7 @@ absl::StatusOr HeaderParser::configure( HeaderAppendAction append_action) { HeaderParserPtr header_parser(new HeaderParser()); + header_parser->headers_to_add_.reserve(headers_to_add.size()); for (const auto& header_value : headers_to_add) { auto entry_or_error = HeadersToAddEntry::create(header_value, append_action); RETURN_IF_NOT_OK_REF(entry_or_error.status()); @@ -120,6 +122,7 @@ HeaderParser::configure(const Protobuf::RepeatedPtrField& hea RETURN_IF_NOT_OK_REF(parser_or_error.status()); HeaderParserPtr header_parser = std::move(parser_or_error.value()); + header_parser->headers_to_remove_.reserve(headers_to_remove.size()); for (const auto& header : headers_to_remove) { // We reject :-prefix (e.g. :path) removal here. This is dangerous, since other aspects of // request finalization assume their existence and they are needed for well-formedness in most