Skip to content

Commit

Permalink
Merge pull request #2960 from preactjs/diffchildren-size-optimizations
Browse files Browse the repository at this point in the history
Size optimizations for excessDomChildren
  • Loading branch information
marvinhagemeister authored Jan 24, 2021
2 parents 47c521d + 44f17a1 commit a7fc0b3
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,30 +300,25 @@ function diffElementNodes(
commitQueue,
isHydrating
) {
let i;
let oldProps = oldVNode.props;
let newProps = newVNode.props;
let nodeType = newVNode.type;
let i = 0;

// Tracks entering and exiting SVG namespace when descending through the tree.
if (nodeType === 'svg') isSvg = true;

if (excessDomChildren != null) {
for (i = 0; i < excessDomChildren.length; i++) {
for (; i < excessDomChildren.length; i++) {
const child = excessDomChildren[i];

// if newVNode matches an element in excessDomChildren or the `dom`
// argument matches an element in excessDomChildren, remove it from
// excessDomChildren so it isn't later removed in diffChildren
//
// Note: This takes advantage of Text nodes having `.localName=undefined`,
// which is loosely equal to Text VNodes' `.type=null`. Elements use string equality.
if (
child != null &&
((nodeType === null
? child.nodeType === 3
: child.localName === nodeType) ||
dom == child)
child &&
(child === dom ||
(nodeType ? child.localName == nodeType : child.nodeType == 3))
) {
dom = child;
excessDomChildren[i] = null;
Expand Down Expand Up @@ -364,9 +359,9 @@ function diffElementNodes(
dom.data = newProps;
}
} else {
if (excessDomChildren != null) {
excessDomChildren = EMPTY_ARR.slice.call(dom.childNodes);
}
// If excessDomChildren was not null, repopulate it with the current element's children:
excessDomChildren =
excessDomChildren && EMPTY_ARR.slice.call(dom.childNodes);

oldProps = oldVNode.props || EMPTY_OBJ;

Expand Down

0 comments on commit a7fc0b3

Please sign in to comment.