Skip to content

Commit 6e0055d

Browse files
authored
access-log: refactor the ResponseFlagFilter and remove an redundant boolean flag (#41030)
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
1 parent 33a359f commit 6e0055d

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

source/common/access_log/access_log_impl.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,27 @@ bool HeaderFilter::evaluate(const Formatter::HttpFormatterContext& context,
217217
}
218218

219219
ResponseFlagFilter::ResponseFlagFilter(
220-
const envoy::config::accesslog::v3::ResponseFlagFilter& config)
221-
: has_configured_flags_(!config.flags().empty()) {
222-
223-
// Preallocate the vector to avoid frequent heap allocations.
224-
configured_flags_.resize(StreamInfo::ResponseFlagUtils::responseFlagsVec().size(), false);
225-
for (int i = 0; i < config.flags_size(); i++) {
226-
auto response_flag = StreamInfo::ResponseFlagUtils::toResponseFlag(config.flags(i));
227-
// The config has been validated. Therefore, every flag in the config will have a mapping.
228-
ASSERT(response_flag.has_value());
229-
230-
// The vector is allocated with the size of the response flags vec. Therefore, the index
231-
// should always be valid.
232-
ASSERT(response_flag.value().value() < configured_flags_.size());
233-
234-
configured_flags_[response_flag.value().value()] = true;
220+
const envoy::config::accesslog::v3::ResponseFlagFilter& config) {
221+
if (!config.flags().empty()) {
222+
// Preallocate the vector to avoid frequent heap allocations.
223+
configured_flags_.resize(StreamInfo::ResponseFlagUtils::responseFlagsVec().size(), false);
224+
for (int i = 0; i < config.flags_size(); i++) {
225+
auto response_flag = StreamInfo::ResponseFlagUtils::toResponseFlag(config.flags(i));
226+
// The config has been validated. Therefore, every flag in the config will have a mapping.
227+
ASSERT(response_flag.has_value());
228+
229+
// The vector is allocated with the size of the response flags vec. Therefore, the index
230+
// should always be valid.
231+
ASSERT(response_flag.value().value() < configured_flags_.size());
232+
233+
configured_flags_[response_flag.value().value()] = true;
234+
}
235235
}
236236
}
237237

238238
bool ResponseFlagFilter::evaluate(const Formatter::HttpFormatterContext&,
239239
const StreamInfo::StreamInfo& info) const {
240-
if (has_configured_flags_) {
240+
if (!configured_flags_.empty()) {
241241
for (const auto flag : info.responseFlags()) {
242242
ASSERT(flag.value() < configured_flags_.size());
243243
if (configured_flags_[flag.value()]) {

source/common/access_log/access_log_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ class ResponseFlagFilter : public Filter {
188188
const StreamInfo::StreamInfo& info) const override;
189189

190190
private:
191-
const bool has_configured_flags_{};
192191
std::vector<bool> configured_flags_{};
193192
};
194193

0 commit comments

Comments
 (0)