Skip to content

Commit 4f2af1c

Browse files
authored
improve perf by reducing prop access (#3956)
1 parent 87e5083 commit 4f2af1c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/diff/children.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { diff, unmount, applyRef } from './index';
22
import { createVNode, Fragment } from '../create-element';
33
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
44
import { getDomSibling } from '../component';
5+
import { isArray } from '../util';
56

67
/**
78
* Diff the children of a virtual node
@@ -70,7 +71,7 @@ export function diffChildren(
7071
null,
7172
childVNode
7273
);
73-
} else if (Array.isArray(childVNode)) {
74+
} else if (isArray(childVNode)) {
7475
childVNode = newParentVNode._children[i] = createVNode(
7576
Fragment,
7677
{ children: childVNode },
@@ -265,7 +266,7 @@ function reorderChildren(childVNode, oldDom, parentDom) {
265266
export function toChildArray(children, out) {
266267
out = out || [];
267268
if (children == null || typeof children == 'boolean') {
268-
} else if (Array.isArray(children)) {
269+
} else if (isArray(children)) {
269270
children.some(child => {
270271
toChildArray(child, out);
271272
});

src/diff/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, getDomSibling } from '../component';
33
import { Fragment } from '../create-element';
44
import { diffChildren } from './children';
55
import { diffProps, setProperty } from './props';
6-
import { assign, removeNode, slice } from '../util';
6+
import { assign, isArray, removeNode, slice } from '../util';
77
import options from '../options';
88

99
/**
@@ -232,7 +232,7 @@ export function diff(
232232

233233
diffChildren(
234234
parentDom,
235-
Array.isArray(renderResult) ? renderResult : [renderResult],
235+
isArray(renderResult) ? renderResult : [renderResult],
236236
newVNode,
237237
oldVNode,
238238
globalContext,
@@ -438,7 +438,7 @@ function diffElementNodes(
438438
i = newVNode.props.children;
439439
diffChildren(
440440
dom,
441-
Array.isArray(i) ? i : [i],
441+
isArray(i) ? i : [i],
442442
newVNode,
443443
oldVNode,
444444
globalContext,

src/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { EMPTY_ARR } from './constants';
22

3+
export const isArray = Array.isArray;
4+
35
/**
46
* Assign properties from `props` to `obj`
57
* @template O, P The obj and props types

0 commit comments

Comments
 (0)