From e111ce2b4b422babc40bf27933995c0442475b84 Mon Sep 17 00:00:00 2001 From: Kuat Yessenov Date: Wed, 11 Oct 2023 21:45:26 +0000 Subject: [PATCH] review Signed-off-by: Kuat Yessenov --- .../common/set_filter_state/filter_config.cc | 13 ++++++------- .../common/set_filter_state/filter_config.h | 14 ++++++-------- .../common/set_filter_state/filter_config_test.cc | 9 ++++----- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/source/extensions/filters/common/set_filter_state/filter_config.cc b/source/extensions/filters/common/set_filter_state/filter_config.cc index 789387eb33c1..b6e7d8edd7b5 100644 --- a/source/extensions/filters/common/set_filter_state/filter_config.cc +++ b/source/extensions/filters/common/set_filter_state/filter_config.cc @@ -8,10 +8,9 @@ namespace Filters { namespace Common { namespace SetFilterState { -std::vector Config::parse( - const Protobuf::RepeatedPtrField< - envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values, - Server::Configuration::CommonFactoryContext& context) const { +std::vector +Config::parse(const Protobuf::RepeatedPtrField& proto_values, + Server::Configuration::CommonFactoryContext& context) const { std::vector values; values.reserve(proto_values.size()); for (const auto& proto_value : proto_values) { @@ -24,10 +23,10 @@ std::vector Config::parse( } value.state_type_ = proto_value.read_only() ? StateType::ReadOnly : StateType::Mutable; switch (proto_value.shared_with_upstream()) { - case envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue::ONCE: + case FilterStateValueProto::ONCE: value.stream_sharing_ = StreamSharing::SharedWithUpstreamConnectionOnce; break; - case envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue::TRANSITIVE: + case FilterStateValueProto::TRANSITIVE: value.stream_sharing_ = StreamSharing::SharedWithUpstreamConnection; break; default: @@ -37,7 +36,7 @@ std::vector Config::parse( value.skip_if_empty_ = proto_value.skip_if_empty(); value.value_ = Formatter::SubstitutionFormatStringUtils::fromProtoConfig( proto_value.format_string(), context); - values.push_back(value); + values.push_back(std::move(value)); } return values; } diff --git a/source/extensions/filters/common/set_filter_state/filter_config.h b/source/extensions/filters/common/set_filter_state/filter_config.h index 53962ea773fc..37d836345eda 100644 --- a/source/extensions/filters/common/set_filter_state/filter_config.h +++ b/source/extensions/filters/common/set_filter_state/filter_config.h @@ -16,6 +16,8 @@ namespace SetFilterState { using LifeSpan = StreamInfo::FilterState::LifeSpan; using StateType = StreamInfo::FilterState::StateType; using StreamSharing = StreamInfo::StreamSharingMayImpactPooling; +using FilterStateValueProto = + envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue; struct Value { std::string key_; @@ -28,19 +30,15 @@ struct Value { class Config : public Logger::Loggable { public: - Config( - const Protobuf::RepeatedPtrField< - envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values, - LifeSpan life_span, Server::Configuration::CommonFactoryContext& context) + Config(const Protobuf::RepeatedPtrField& proto_values, LifeSpan life_span, + Server::Configuration::CommonFactoryContext& context) : life_span_(life_span), values_(parse(proto_values, context)) {} void updateFilterState(const Formatter::HttpFormatterContext& context, StreamInfo::StreamInfo& info) const; private: - std::vector parse( - const Protobuf::RepeatedPtrField< - envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values, - Server::Configuration::CommonFactoryContext& context) const; + std::vector parse(const Protobuf::RepeatedPtrField& proto_values, + Server::Configuration::CommonFactoryContext& context) const; const LifeSpan life_span_; const std::vector values_; }; diff --git a/test/extensions/filters/common/set_filter_state/filter_config_test.cc b/test/extensions/filters/common/set_filter_state/filter_config_test.cc index e82db7cf3901..9cfd19a775f1 100644 --- a/test/extensions/filters/common/set_filter_state/filter_config_test.cc +++ b/test/extensions/filters/common/set_filter_state/filter_config_test.cc @@ -43,17 +43,16 @@ class ConfigTest : public testing::Test { public: void initialize(const std::vector& values, LifeSpan life_span = LifeSpan::FilterChain) { - using ProtoValue = envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue; - std::vector proto_values; + std::vector proto_values; proto_values.reserve(values.size()); for (const auto& value : values) { - ProtoValue proto_value; + FilterStateValueProto proto_value; TestUtility::loadFromYaml(value, proto_value); proto_values.push_back(proto_value); } config_ = std::make_shared( - Protobuf::RepeatedPtrField(proto_values.begin(), proto_values.end()), life_span, - context_); + Protobuf::RepeatedPtrField(proto_values.begin(), proto_values.end()), + life_span, context_); } void update() { config_->updateFilterState({&header_map_}, info_); } NiceMock context_;