@@ -60,8 +60,15 @@ CompoundWrite CompoundWrite::EmptyWrite() { return CompoundWrite(); }
6060
6161CompoundWrite CompoundWrite::AddWrite (const Path& path,
6262 const Optional<Variant>& variant) const {
63+ CompoundWrite target = *this ;
64+ target.AddWriteInline (path, variant);
65+ return target;
66+ }
67+
68+ void CompoundWrite::AddWriteInline (const Path& path,
69+ const Optional<Variant>& variant) {
6370 if (path.empty ()) {
64- return CompoundWrite (Tree<Variant>(variant));
71+ * this = CompoundWrite (Tree<Variant>(variant));
6572 } else {
6673 Optional<Path> root_most_path = write_tree_.FindRootMostPathWithValue (path);
6774 if (root_most_path.has_value ()) {
@@ -78,18 +85,13 @@ CompoundWrite CompoundWrite::AddWrite(const Path& path,
7885 if (!relative_path->empty () && IsPriorityKey (back) &&
7986 VariantIsEmpty (VariantGetChild (value, relative_path->GetParent ()))) {
8087 // Ignore priority updates on empty variants
81- return *this ;
8288 } else {
83- CompoundWrite result = *this ;
8489 Variant updated_variant = *value;
8590 VariantUpdateChild (&updated_variant, *relative_path, *variant);
86- result.write_tree_ .SetValueAt (*root_most_path, updated_variant);
87- return result;
91+ write_tree_.SetValueAt (*root_most_path, updated_variant);
8892 }
8993 } else {
90- CompoundWrite result = *this ;
91- result.write_tree_ .SetValueAt (path, variant);
92- return result;
94+ write_tree_.SetValueAt (path, variant);
9395 }
9496 }
9597}
@@ -109,6 +111,20 @@ CompoundWrite CompoundWrite::AddWrite(const std::string& key,
109111 return AddWrite (Path (key), Optional<Variant>(value));
110112}
111113
114+ void CompoundWrite::AddWriteInline (const Path& path, const Variant& value) {
115+ AddWriteInline (path, Optional<Variant>(value));
116+ }
117+
118+ void CompoundWrite::AddWriteInline (const std::string& key,
119+ const Optional<Variant>& value) {
120+ AddWriteInline (Path (key), value);
121+ }
122+
123+ void CompoundWrite::AddWriteInline (const std::string& key,
124+ const Variant& value) {
125+ AddWriteInline (Path (key), Optional<Variant>(value));
126+ }
127+
112128CompoundWrite CompoundWrite::AddWrites (const Path& path,
113129 const CompoundWrite& updates) const {
114130 return updates.write_tree_ .Fold (
@@ -118,6 +134,15 @@ CompoundWrite CompoundWrite::AddWrites(const Path& path,
118134 });
119135}
120136
137+ void CompoundWrite::AddWritesInline (const Path& path,
138+ const CompoundWrite& updates) {
139+ updates.write_tree_ .Fold (
140+ 0 , [&path, this ](Path relative_path, Variant value, int ) {
141+ AddWriteInline (path.GetChild (relative_path), Optional<Variant>(value));
142+ return 0 ;
143+ });
144+ }
145+
121146CompoundWrite CompoundWrite::RemoveWrite (const Path& path) const {
122147 if (path.empty ()) {
123148 return CompoundWrite ();
@@ -133,6 +158,18 @@ CompoundWrite CompoundWrite::RemoveWrite(const Path& path) const {
133158 return CompoundWrite ();
134159}
135160
161+ void CompoundWrite::RemoveWriteInline (const Path& path) {
162+ if (path.empty ()) {
163+ *this = CompoundWrite ();
164+ } else {
165+ Tree<Variant>* subtree = write_tree_.GetChild (path);
166+ if (subtree) {
167+ subtree->children ().clear ();
168+ subtree->value ().reset ();
169+ }
170+ }
171+ }
172+
136173bool CompoundWrite::HasCompleteWrite (const Path& path) const {
137174 return GetCompleteVariant (path).has_value ();
138175}
0 commit comments