Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(core): test perf of less arguments #4367

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -493,9 +495,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