Skip to content

Commit 7259ee4

Browse files
authored
Check slice oldChildren perf
1 parent b864138 commit 7259ee4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/diff/children.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ function constructNewChildrenArray(
166166

167167
let skew = 0;
168168

169-
newParentVNode._children = new Array(newChildrenLength);
169+
const newChildren = oldChildren.slice();
170+
newChildren.length = newChildrenLength;
171+
newParentVNode._children = newChildren;
170172
for (i = 0; i < newChildrenLength; i++) {
171173
// @ts-expect-error We are reusing the childVNode variable to hold both the
172174
// pre and post normalized childVNode
@@ -177,7 +179,7 @@ function constructNewChildrenArray(
177179
typeof childVNode == 'boolean' ||
178180
typeof childVNode == 'function'
179181
) {
180-
childVNode = newParentVNode._children[i] = null;
182+
newChildren[i] = null;
181183
continue;
182184
}
183185
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
@@ -190,15 +192,15 @@ function constructNewChildrenArray(
190192
typeof childVNode == 'bigint' ||
191193
childVNode.constructor == String
192194
) {
193-
childVNode = newParentVNode._children[i] = createVNode(
195+
childVNode = newChildren[i] = createVNode(
194196
null,
195197
childVNode,
196198
null,
197199
null,
198200
null
199201
);
200202
} else if (isArray(childVNode)) {
201-
childVNode = newParentVNode._children[i] = createVNode(
203+
childVNode = newChildren[i] = createVNode(
202204
Fragment,
203205
{ children: childVNode },
204206
null,
@@ -210,15 +212,15 @@ function constructNewChildrenArray(
210212
// scenario:
211213
// const reuse = <div />
212214
// <div>{reuse}<span />{reuse}</div>
213-
childVNode = newParentVNode._children[i] = createVNode(
215+
childVNode = newChildren[i] = createVNode(
214216
childVNode.type,
215217
childVNode.props,
216218
childVNode.key,
217219
childVNode.ref ? childVNode.ref : null,
218220
childVNode._original
219221
);
220222
} else {
221-
childVNode = newParentVNode._children[i] = childVNode;
223+
childVNode = newChildren[i] = childVNode;
222224
}
223225

224226
const skewedIndex = i + skew;

0 commit comments

Comments
 (0)