From 4f2af1c191d9b7400403a8f8d904c9e3a5e4f8d2 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 31 Mar 2023 08:02:04 +0200 Subject: [PATCH] improve perf by reducing prop access (#3956) --- src/diff/children.js | 5 +++-- src/diff/index.js | 6 +++--- src/util.js | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index 6487b55b4c..4c388ed6f3 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -2,6 +2,7 @@ import { diff, unmount, applyRef } from './index'; import { createVNode, Fragment } from '../create-element'; import { EMPTY_OBJ, EMPTY_ARR } from '../constants'; import { getDomSibling } from '../component'; +import { isArray } from '../util'; /** * Diff the children of a virtual node @@ -70,7 +71,7 @@ export function diffChildren( null, childVNode ); - } else if (Array.isArray(childVNode)) { + } else if (isArray(childVNode)) { childVNode = newParentVNode._children[i] = createVNode( Fragment, { children: childVNode }, @@ -265,7 +266,7 @@ function reorderChildren(childVNode, oldDom, parentDom) { export function toChildArray(children, out) { out = out || []; if (children == null || typeof children == 'boolean') { - } else if (Array.isArray(children)) { + } else if (isArray(children)) { children.some(child => { toChildArray(child, out); }); diff --git a/src/diff/index.js b/src/diff/index.js index b6243a8bef..477663cd9e 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -3,7 +3,7 @@ import { Component, getDomSibling } from '../component'; import { Fragment } from '../create-element'; import { diffChildren } from './children'; import { diffProps, setProperty } from './props'; -import { assign, removeNode, slice } from '../util'; +import { assign, isArray, removeNode, slice } from '../util'; import options from '../options'; /** @@ -232,7 +232,7 @@ export function diff( diffChildren( parentDom, - Array.isArray(renderResult) ? renderResult : [renderResult], + isArray(renderResult) ? renderResult : [renderResult], newVNode, oldVNode, globalContext, @@ -438,7 +438,7 @@ function diffElementNodes( i = newVNode.props.children; diffChildren( dom, - Array.isArray(i) ? i : [i], + isArray(i) ? i : [i], newVNode, oldVNode, globalContext, diff --git a/src/util.js b/src/util.js index 0e9b3b1e56..1c4b499bff 100644 --- a/src/util.js +++ b/src/util.js @@ -1,5 +1,7 @@ import { EMPTY_ARR } from './constants'; +export const isArray = Array.isArray; + /** * Assign properties from `props` to `obj` * @template O, P The obj and props types