on master help sign in
Have a fast path for removing all children
649bef1Nick Fitzgerald
src/diff.rs+20
@@ -190,6 +190,13 @@ fn diff_children(
190 new: &[Node],
190 new: &[Node],
191 cached_roots: &mut FxHashSet<CacheId>,
191 cached_roots: &mut FxHashSet<CacheId>,
192) {
192) {
193+ if new.is_empty() {
194+ if !old.is_empty() {
195+ remove_children(change_list, registry, old);
196+ }
197+ return;
198+ }
199+
193 debug!(" updating children shared by old and new");
200 debug!(" updating children shared by old and new");
194
201
195 let num_children_to_diff = cmp::min(new.len(), old.len());
202 let num_children_to_diff = cmp::min(new.len(), old.len());
@@ -255,6 +262,19 @@ fn diff_children(
255 }
262 }
256}
263}
257
264
265+fn remove_children(
266+ change_list: &mut ChangeListBuilder,
267+ registry: &mut EventsRegistry,
268+ old: &[Node],
269+) {
270+ for child in old {
271+ registry.remove_subtree(child);
272+ }
273+ // Fast way to remove all children: set the node's textContent to an empty
274+ // string.
275+ change_list.set_text("");
276+}
277+
258fn create(
278fn create(
259 cached_set: &CachedSet,
279 cached_set: &CachedSet,
260 change_list: &mut ChangeListBuilder,
280 change_list: &mut ChangeListBuilder,