Skip to content

Commit

Permalink
test perf of less arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Apr 30, 2024
1 parent a832512 commit 6c28c2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getDomSibling } from '../component';
* Diff the children of a virtual node
* @param {PreactElement} parentDom The DOM element whose children are being
* diffed
* @param {ComponentChildren[]} renderResult
* @param {VNode} newParentVNode The new virtual node whose children should be
* diff'ed against oldParentVNode
* @param {VNode} oldParentVNode The old virtual node whose children should be
Expand All @@ -28,7 +27,6 @@ import { getDomSibling } from '../component';
*/
export function diffChildren(
parentDom,
renderResult,
newParentVNode,
oldParentVNode,
globalContext,
Expand All @@ -54,10 +52,14 @@ export function diffChildren(
/** @type {VNode[]} */
let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;

let newChildrenLength = renderResult.length;
let newChildrenLength = newParentVNode._children.length;

newParentVNode._nextDom = oldDom;
constructNewChildrenArray(newParentVNode, renderResult, oldChildren);
constructNewChildrenArray(
newParentVNode,
newParentVNode._children,
oldChildren
);
oldDom = newParentVNode._nextDom;

for (i = 0; i < newChildrenLength; i++) {
Expand Down
7 changes: 5 additions & 2 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ export function diff(
tmp != null && tmp.type === Fragment && tmp.key == null;
let renderResult = isTopLevelFragment ? tmp.props.children : tmp;

newVNode._children = isArray(renderResult)
? renderResult
: [renderResult];
diffChildren(
parentDom,
isArray(renderResult) ? renderResult : [renderResult],
newVNode,
oldVNode,
globalContext,
Expand Down Expand Up @@ -490,9 +492,10 @@ function diffElementNodes(
} else {
if (oldHtml) dom.innerHTML = '';

// @ts-expect-error
newVNode._children = isArray(newChildren) ? newChildren : [newChildren];
diffChildren(
dom,
isArray(newChildren) ? newChildren : [newChildren],
newVNode,
oldVNode,
globalContext,
Expand Down

0 comments on commit 6c28c2d

Please sign in to comment.