@@ -32,7 +32,7 @@ namespace model {
32
32
namespace {
33
33
34
34
using nanopb::FieldsArray;
35
- using nanopb::FreeNanopbMessage ;
35
+ using nanopb::FreeFieldsArray ;
36
36
using nanopb::MakeArray;
37
37
using nanopb::MakeBytesArray;
38
38
using nanopb::MakeString;
@@ -73,7 +73,7 @@ google_firestore_v1_MapValue_FieldsEntry* FindEntry(
73
73
}
74
74
75
75
size_t CalculateSizeOfUnion (
76
- google_firestore_v1_MapValue* map_value,
76
+ const google_firestore_v1_MapValue& map_value,
77
77
const std::map<std::string, google_firestore_v1_Value>& upserts,
78
78
const std::set<std::string>& deletes) {
79
79
// Compute the size of the map after applying all mutations. The final size is
@@ -104,7 +104,7 @@ void ApplyChanges(
104
104
auto source_count = parent->fields_count ;
105
105
auto * source_fields = parent->fields ;
106
106
107
- size_t target_count = CalculateSizeOfUnion (parent, upserts, deletes);
107
+ size_t target_count = CalculateSizeOfUnion (* parent, upserts, deletes);
108
108
auto * target_fields =
109
109
MakeArray<google_firestore_v1_MapValue_FieldsEntry>(target_count);
110
110
@@ -115,24 +115,26 @@ void ApplyChanges(
115
115
for (pb_size_t source_index = 0 , target_index = 0 ;
116
116
target_index < target_count;) {
117
117
if (source_index < source_count) {
118
- std::string key = MakeString (source_fields[source_index].key );
118
+ auto & source_entry = source_fields[source_index];
119
+ auto & target_entry = target_fields[target_index];
120
+
121
+ std::string source_key = MakeString (source_entry.key );
119
122
120
123
// Check if the source key is deleted
121
- if (delete_it != deletes.end () && *delete_it == key) {
122
- FreeNanopbMessage (google_firestore_v1_MapValue_FieldsEntry_fields,
123
- source_fields + source_index);
124
+ if (delete_it != deletes.end () && *delete_it == source_key) {
125
+ FreeFieldsArray (&source_entry);
124
126
125
127
++delete_it;
126
128
++source_index;
127
129
continue ;
128
130
}
129
131
130
132
// Check if the source key is updated by the next upsert
131
- if (upsert_it != upserts.end () && upsert_it->first == key ) {
132
- FreeNanopbMessage (google_firestore_v1_Value_fields,
133
- &source_fields[source_index]. value );
134
- target_fields[target_index] .key = source_fields[source_index] .key ;
135
- target_fields[target_index] .value = DeepClone (upsert_it->second );
133
+ if (upsert_it != upserts.end () && upsert_it->first == source_key ) {
134
+ FreeFieldsArray (&source_entry. value );
135
+
136
+ target_entry .key = source_entry .key ;
137
+ target_entry .value = DeepClone (upsert_it->second );
136
138
137
139
++upsert_it;
138
140
++source_index;
@@ -141,8 +143,8 @@ void ApplyChanges(
141
143
}
142
144
143
145
// Check if the source key comes before the next upsert
144
- if (upsert_it == upserts.end () || upsert_it->first > key ) {
145
- target_fields[target_index] = source_fields[source_index] ;
146
+ if (upsert_it == upserts.end () || upsert_it->first > source_key ) {
147
+ target_entry = source_entry ;
146
148
147
149
++source_index;
148
150
++target_index;
@@ -151,8 +153,8 @@ void ApplyChanges(
151
153
}
152
154
153
155
// Otherwise, insert the next upsert.
154
- target_fields[target_index] .key = MakeBytesArray (upsert_it->first );
155
- target_fields[target_index] .value = DeepClone (upsert_it->second );
156
+ target_entry .key = MakeBytesArray (upsert_it->first );
157
+ target_entry .value = DeepClone (upsert_it->second );
156
158
157
159
++upsert_it;
158
160
++target_index;
@@ -181,11 +183,11 @@ FieldMask MutableObjectValue::ExtractFieldMask(
181
183
182
184
for (size_t i = 0 ; i < value.fields_count ; ++i) {
183
185
const google_firestore_v1_MapValue_FieldsEntry& entry = value.fields [i];
184
- FieldPath current_path ( {MakeString (entry.key )}) ;
186
+ FieldPath current_path{MakeString (entry.key )};
185
187
186
188
if (entry.value .which_value_type !=
187
189
google_firestore_v1_Value_map_value_tag) {
188
- fields.insert (std::move (( current_path) ));
190
+ fields.insert (std::move (current_path));
189
191
continue ;
190
192
}
191
193
@@ -263,7 +265,7 @@ void MutableObjectValue::SetAll(const FieldMask& field_mask,
263
265
}
264
266
265
267
void MutableObjectValue::Delete (const FieldPath& path) {
266
- HARD_ASSERT (!path.empty (), " Cannot set field for empty path on ObjectValue " );
268
+ HARD_ASSERT (!path.empty (), " Cannot delete field with empty path" );
267
269
268
270
google_firestore_v1_Value* nested_value = value_.get ();
269
271
for (const std::string& segment : path.PopLast ()) {
@@ -302,8 +304,7 @@ google_firestore_v1_MapValue* MutableObjectValue::ParentMap(
302
304
google_firestore_v1_Value_map_value_tag) {
303
305
// Since the element is not a map value, free all existing data and
304
306
// change it to a map type.
305
- FreeNanopbMessage (FieldsArray<google_firestore_v1_Value>(),
306
- &entry->value );
307
+ FreeFieldsArray (&entry->value );
307
308
entry->value .which_value_type = google_firestore_v1_Value_map_value_tag;
308
309
}
309
310
0 commit comments