|
28 | 28 | #include "absl/strings/str_cat.h"
|
29 | 29 | #include "absl/strings/str_join.h"
|
30 | 30 | #include "absl/strings/string_view.h"
|
31 |
| -#include "src/google/protobuf/util/converter/utility.h" |
| 31 | +#include "ocpdiag/core/compat/status_macros.h" |
32 | 32 | #include "proto_processing_lib/proto_scrubber/constants.h"
|
33 | 33 | #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" |
35 | 35 |
|
36 | 36 | namespace proto_processing_lib::proto_scrubber {
|
37 | 37 |
|
38 |
| - |
39 |
| -namespace { |
40 |
| - |
41 | 38 | using google::protobuf::util::converter::ToSnakeCase;
|
42 | 39 |
|
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 |
| - |
66 | 40 | FieldMaskNode::FieldMaskNode(
|
67 | 41 | const google::protobuf::Type* type, bool is_leaf, bool is_map,
|
68 | 42 | bool all_keys_included,
|
@@ -106,23 +80,24 @@ const google::protobuf::Field* FieldMaskNode::FindChildField(
|
106 | 80 | // method is called).
|
107 | 81 | if (child_name_child_map_.empty()) {
|
108 | 82 | 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); |
110 | 84 | }
|
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); |
123 | 92 | }
|
| 93 | + for (const google::protobuf::Field& field : |
| 94 | + type_finder_(kStructListValueTypeUrl)->fields()) { |
| 95 | + child_name_child_map_.try_emplace(field.name(), &field); |
| 96 | + } |
| 97 | + } |
124 | 98 | }
|
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; |
126 | 101 | }
|
127 | 102 |
|
128 | 103 | absl::Status FieldMaskNode::ParseFieldNameAndMapKey(const std::string& segment,
|
|
0 commit comments