fixed `Each` clear opt

This commit is contained in:
Jose Quesada 2022-11-28 17:26:48 -06:00
parent 698527ddf6
commit 0b72c5550b
1 changed files with 7 additions and 4 deletions

View File

@ -321,10 +321,6 @@ fn diff<K: Eq + Hash>(
let added_amount = cmds.len() - moved_amount - removed_amount;
let delta = (added_amount as isize) - (removed_amount as isize);
if cmds.is_empty() {
cmds.push(DiffOp::Clear);
}
Diff {
added_delta: delta,
moving: moved_amount,
@ -393,6 +389,13 @@ fn apply_cmds<T, EF, N>(
// we risk overwriting one of the values
let mut items_to_move = Vec::with_capacity(cmds.moving);
// We can optimize for the case when the items are cleared
if items.is_empty() && !cmds.ops.is_empty() {
cmds.ops.clear();
cmds.ops.push(DiffOp::Clear);
}
// We can optimize the case of replacing all items
if !children.is_empty() && cmds.removing == children.len() {
children.clear();