Skip to content

Commit ea2f7b2

Browse files
committed
[minor] Make map functions inline
1 parent 03a77a0 commit ea2f7b2

File tree

6 files changed

+24
-53
lines changed

6 files changed

+24
-53
lines changed

bazel-bin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/local/google/home/dchakarwarti/.cache/bazel/_bazel_dchakarwarti/2bbf26c7866faddfb80004c79cb2f937/execroot/proto_processing_lib/bazel-out/k8-fastbuild/bin

bazel-out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/local/google/home/dchakarwarti/.cache/bazel/_bazel_dchakarwarti/2bbf26c7866faddfb80004c79cb2f937/execroot/proto_processing_lib/bazel-out

bazel-proto_processing_lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/local/google/home/dchakarwarti/.cache/bazel/_bazel_dchakarwarti/2bbf26c7866faddfb80004c79cb2f937/execroot/proto_processing_lib

bazel-testlogs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/local/google/home/dchakarwarti/.cache/bazel/_bazel_dchakarwarti/2bbf26c7866faddfb80004c79cb2f937/execroot/proto_processing_lib/bazel-out/k8-fastbuild/testlogs

proto_processing_lib/proto_scrubber/cloud_audit_log_field_checker.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ namespace {
3232
// Returns pointer to message type name, or nullptr if field isn't a message or
3333
// has an unknown type. Caller does not own returned pointer.
3434
const std::string* GetMessageTypeName(const FieldMaskNode* node);
35-
36-
const FieldMaskNode* FindPtrOrNull(
37-
absl::flat_hash_map<std::string, const FieldMaskNode*> type_to_node,
38-
const std::string& type_name) {
39-
const auto& it = type_to_node.find(type_name);
40-
if (it == type_to_node.end()) {
41-
return nullptr;
42-
}
43-
return it->second;
44-
}
4535
} // namespace
4636

4737
CloudAuditLogFieldChecker::CloudAuditLogFieldChecker(
@@ -78,7 +68,9 @@ FieldCheckResults CloudAuditLogFieldChecker::CheckField(
7868
const std::string* type_name = GetMessageTypeName(current_node);
7969

8070
if (type_name != nullptr) {
81-
const FieldMaskNode* found_node = FindPtrOrNull(type_to_node, *type_name);
71+
const auto& it = type_to_node.find(*type_name);
72+
const FieldMaskNode* found_node =
73+
it != type_to_node.end() ? it->second : nullptr;
8274
if (found_node == nullptr) {
8375
// Keep track of this message type in case it's cyclic.
8476
type_to_node.emplace(*type_name, current_node);

proto_processing_lib/proto_scrubber/field_mask_node.cc

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,15 @@
2828
#include "absl/strings/str_cat.h"
2929
#include "absl/strings/str_join.h"
3030
#include "absl/strings/string_view.h"
31-
#include "src/google/protobuf/util/converter/utility.h"
31+
#include "ocpdiag/core/compat/status_macros.h"
3232
#include "proto_processing_lib/proto_scrubber/constants.h"
3333
#include "proto_processing_lib/proto_scrubber/utility.h"
34-
#include "ocpdiag/core/compat/status_macros.h"
34+
#include "src/google/protobuf/util/converter/utility.h"
3535

3636
namespace proto_processing_lib::proto_scrubber {
3737

38-
39-
namespace {
40-
4138
using google::protobuf::util::converter::ToSnakeCase;
4239

43-
void InsertIfNotPresent(
44-
absl::flat_hash_map<absl::string_view, const google::protobuf::Field*>&
45-
child_name_child_map,
46-
absl::string_view field_name, const google::protobuf::Field* field) {
47-
if (!child_name_child_map.contains(field_name)) {
48-
child_name_child_map.emplace(field_name, field);
49-
}
50-
}
51-
52-
const google::protobuf::Field* FindWithDefault(
53-
absl::flat_hash_map<absl::string_view, const google::protobuf::Field*>&
54-
child_name_child_map,
55-
absl::string_view field_name) {
56-
const auto& it = child_name_child_map.find(field_name);
57-
if (it == child_name_child_map.end()) {
58-
google::protobuf::Field* field = nullptr;
59-
return field;
60-
}
61-
return it->second;
62-
}
63-
64-
} // namespace
65-
6640
FieldMaskNode::FieldMaskNode(
6741
const google::protobuf::Type* type, bool is_leaf, bool is_map,
6842
bool all_keys_included,
@@ -106,23 +80,24 @@ const google::protobuf::Field* FieldMaskNode::FindChildField(
10680
// method is called).
10781
if (child_name_child_map_.empty()) {
10882
for (const google::protobuf::Field& field : type_->fields()) {
109-
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
83+
child_name_child_map_.try_emplace(field.name(), &field);
11084
}
111-
if (type_->name() == kStructType || type_->name() == kStructValueType ||
112-
type_->name() == kStructListValueType) {
113-
// Add Struct type fields and List type fields for nested searching.
114-
// A Struct value can be List. A List value can be Struct.
115-
for (const google::protobuf::Field& field :
116-
type_finder_(kStructTypeUrl)->fields()) {
117-
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
118-
}
119-
for (const google::protobuf::Field& field :
120-
type_finder_(kStructListValueTypeUrl)->fields()) {
121-
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
122-
}
85+
if (type_->name() == kStructType || type_->name() == kStructValueType ||
86+
type_->name() == kStructListValueType) {
87+
// Add Struct type fields and List type fields for nested searching.
88+
// A Struct value can be List. A List value can be Struct.
89+
for (const google::protobuf::Field& field :
90+
type_finder_(kStructTypeUrl)->fields()) {
91+
child_name_child_map_.try_emplace(field.name(), &field);
12392
}
93+
for (const google::protobuf::Field& field :
94+
type_finder_(kStructListValueTypeUrl)->fields()) {
95+
child_name_child_map_.try_emplace(field.name(), &field);
96+
}
97+
}
12498
}
125-
return FindWithDefault(child_name_child_map_, field_name);
99+
const auto& it = child_name_child_map_.find(field_name);
100+
return it != child_name_child_map_.end() ? it->second : nullptr;
126101
}
127102

128103
absl::Status FieldMaskNode::ParseFieldNameAndMapKey(const std::string& segment,

0 commit comments

Comments
 (0)