Skip to content

Commit

Permalink
optimize child diff
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 20, 2020
1 parent e3591cc commit 3baddc6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/diff/children.js
Expand Up @@ -81,15 +81,16 @@ export function diffChildren(
// Either oldVNode === undefined or oldChildrenLength > 0,
// so after this loop oldVNode == null or oldVNode is a valid value.
for (j = 0; j < oldChildrenLength; j++) {
oldVNode = oldChildren[j];
const idx = (i + ((j >>> 1) ^ -(j & 1))) % oldChildrenLength;
oldVNode = oldChildren[idx];
// If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
// We always match by type (in either case).
if (
oldVNode &&
childVNode.key == oldVNode.key &&
childVNode.type === oldVNode.type
) {
oldChildren[j] = undefined;
oldChildren[idx] = undefined;
break;
}
oldVNode = null;
Expand Down

0 comments on commit 3baddc6

Please sign in to comment.