1313// limitations under the License.
1414
1515#include " database/src/desktop/core/compound_write.h"
16+
1617#include " app/src/assert.h"
1718#include " database/src/desktop/core/tree.h"
1819#include " database/src/desktop/util_desktop.h"
@@ -70,19 +71,18 @@ CompoundWrite CompoundWrite::AddWrite(const Path& path,
7071 // TODO(amablue): Consider making FindRootMostPathWithValue also return
7172 // the remainder and not just the root most path.
7273 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);
7475 std::vector<std::string> directories = relative_path->GetDirectories ();
7576 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 ()))) {
8080 // Ignore priority updates on empty variants
8181 return *this ;
8282 } else {
8383 CompoundWrite result = *this ;
8484 Variant updated_variant = *value;
85- * MakeVariantAtPath (&updated_variant, *relative_path) = *variant;
85+ VariantUpdateChild (&updated_variant, *relative_path, *variant) ;
8686 result.write_tree_ .SetValueAt (*root_most_path, updated_variant);
8787 return result;
8888 }
@@ -144,11 +144,9 @@ const Optional<Variant>& CompoundWrite::GetRootWrite() const {
144144Optional<Variant> CompoundWrite::GetCompleteVariant (const Path& path) const {
145145 Optional<Path> root_most = write_tree_.FindRootMostPathWithValue (path);
146146 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));
152150 } else {
153151 return Optional<Variant>();
154152 }
@@ -213,14 +211,13 @@ Variant CompoundWrite::ApplySubtreeWrite(const Path& relative_path,
213211 Variant variant) const {
214212 if (write_tree->value ().has_value ()) {
215213 // 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 ());
218215 } else {
219216 Optional<Variant> priority_write;
220217 for (auto & key_tree_pair : write_tree->children ()) {
221218 const std::string& child_key = key_tree_pair.first ;
222219 const Tree<Variant>& child_tree = key_tree_pair.second ;
223- if (child_key == " .priority " ) {
220+ if (IsPriorityKey ( child_key) ) {
224221 // Apply priorities at the end so we don't update priorities for
225222 // either empty variants or forget to apply priorities to empty
226223 // variants that are later filled
@@ -235,13 +232,13 @@ Variant CompoundWrite::ApplySubtreeWrite(const Path& relative_path,
235232 }
236233 // If there was a priority write, we only apply it if the variant is not
237234 // empty.
238- if (GetInternalVariant ( &variant, relative_path) != nullptr &&
235+ if (! VariantIsEmpty ( VariantGetChild ( &variant, relative_path)) &&
239236 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 () );
242239 }
243- return variant;
244240 }
241+ return variant;
245242}
246243
247244} // namespace internal
0 commit comments