13
13
// limitations under the License.
14
14
15
15
#include " database/src/desktop/core/compound_write.h"
16
+
16
17
#include " app/src/assert.h"
17
18
#include " database/src/desktop/core/tree.h"
18
19
#include " database/src/desktop/util_desktop.h"
@@ -70,19 +71,18 @@ CompoundWrite CompoundWrite::AddWrite(const Path& path,
70
71
// TODO(amablue): Consider making FindRootMostPathWithValue also return
71
72
// the remainder and not just the root most path.
72
73
Optional<Path> relative_path = Path::GetRelative (*root_most_path, path);
73
- const Variant* value = write_tree_.GetValueAt (root_most_path. value () );
74
+ const Variant* value = write_tree_.GetValueAt (* root_most_path);
74
75
std::vector<std::string> directories = relative_path->GetDirectories ();
75
76
std::string back = directories.empty () ? " " : directories.back ();
76
- const Variant* internal_variant =
77
- GetInternalVariant (value, relative_path->GetParent ());
78
- if (!relative_path->empty () && back == " .priority" &&
79
- (internal_variant == nullptr || internal_variant->is_null ())) {
77
+
78
+ if (!relative_path->empty () && IsPriorityKey (back) &&
79
+ VariantIsEmpty (VariantGetChild (value, relative_path->GetParent ()))) {
80
80
// Ignore priority updates on empty variants
81
81
return *this ;
82
82
} else {
83
83
CompoundWrite result = *this ;
84
84
Variant updated_variant = *value;
85
- * MakeVariantAtPath (&updated_variant, *relative_path) = *variant;
85
+ VariantUpdateChild (&updated_variant, *relative_path, *variant) ;
86
86
result.write_tree_ .SetValueAt (*root_most_path, updated_variant);
87
87
return result;
88
88
}
@@ -144,11 +144,9 @@ const Optional<Variant>& CompoundWrite::GetRootWrite() const {
144
144
Optional<Variant> CompoundWrite::GetCompleteVariant (const Path& path) const {
145
145
Optional<Path> root_most = write_tree_.FindRootMostPathWithValue (path);
146
146
if (root_most.has_value ()) {
147
- const Path& root_most_path = root_most.value ();
148
- const Variant* root_most_value = write_tree_.GetValueAt (root_most_path);
149
- Optional<Path> remaining_path = Path::GetRelative (root_most_path, path);
150
- return OptionalFromPointer (
151
- GetInternalVariant (root_most_value, *remaining_path));
147
+ const Variant* root_most_value = write_tree_.GetValueAt (*root_most);
148
+ Optional<Path> remaining_path = Path::GetRelative (*root_most, path);
149
+ return Optional<Variant>(VariantGetChild (root_most_value, *remaining_path));
152
150
} else {
153
151
return Optional<Variant>();
154
152
}
@@ -213,14 +211,13 @@ Variant CompoundWrite::ApplySubtreeWrite(const Path& relative_path,
213
211
Variant variant) const {
214
212
if (write_tree->value ().has_value ()) {
215
213
// Since there a write is always a leaf, we're done here
216
- *MakeVariantAtPath (&variant, relative_path) = write_tree->value ().value ();
217
- return variant;
214
+ VariantUpdateChild (&variant, relative_path, write_tree->value ().value ());
218
215
} else {
219
216
Optional<Variant> priority_write;
220
217
for (auto & key_tree_pair : write_tree->children ()) {
221
218
const std::string& child_key = key_tree_pair.first ;
222
219
const Tree<Variant>& child_tree = key_tree_pair.second ;
223
- if (child_key == " .priority " ) {
220
+ if (IsPriorityKey ( child_key) ) {
224
221
// Apply priorities at the end so we don't update priorities for
225
222
// either empty variants or forget to apply priorities to empty
226
223
// variants that are later filled
@@ -235,13 +232,13 @@ Variant CompoundWrite::ApplySubtreeWrite(const Path& relative_path,
235
232
}
236
233
// If there was a priority write, we only apply it if the variant is not
237
234
// empty.
238
- if (GetInternalVariant ( &variant, relative_path) != nullptr &&
235
+ if (! VariantIsEmpty ( VariantGetChild ( &variant, relative_path)) &&
239
236
priority_write.has_value ()) {
240
- * MakeVariantAtPath (&variant, relative_path.GetChild (" .priority " )) =
241
- priority_write.value ();
237
+ VariantUpdateChild (&variant, relative_path.GetChild (kPriorityKey ),
238
+ priority_write.value () );
242
239
}
243
- return variant;
244
240
}
241
+ return variant;
245
242
}
246
243
247
244
} // namespace internal
0 commit comments