Skip to content

Commit

Permalink
improve perf by reducing prop access (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Mar 31, 2023
1 parent 87e5083 commit 4f2af1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -232,7 +232,7 @@ export function diff(

diffChildren(
parentDom,
Array.isArray(renderResult) ? renderResult : [renderResult],
isArray(renderResult) ? renderResult : [renderResult],
newVNode,
oldVNode,
globalContext,
Expand Down Expand Up @@ -438,7 +438,7 @@ function diffElementNodes(
i = newVNode.props.children;
diffChildren(
dom,
Array.isArray(i) ? i : [i],
isArray(i) ? i : [i],
newVNode,
oldVNode,
globalContext,
Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4f2af1c

Please sign in to comment.