@@ -133,12 +133,6 @@ export const vnode_diff = (
133
133
/// and is not connected to the tree.
134
134
let vNewNode : VNode | null = null ;
135
135
136
- /// When elements have keys they can be consumed out of order and therefore we can't use nextSibling.
137
- /// In such a case this array will contain the elements after the current location.
138
- /// The array even indices will contains keys and odd indices the vNode.
139
- let vSiblings : Array < string | null | VNode > | null = null ; // See: `SiblingsArray`
140
- let vSiblingsIdx = - 1 ;
141
-
142
136
/// Current set of JSX children.
143
137
let jsxChildren : JSXChildren [ ] = null ! ;
144
138
// Current JSX child.
@@ -278,16 +272,9 @@ export const vnode_diff = (
278
272
* order and can't rely on `vnode_getNextSibling` and instead we need to go by `vSiblings`.
279
273
*/
280
274
function peekNextSibling ( ) {
281
- if ( vSiblings !== null ) {
282
- // We came across a key, and we moved nodes around. This means we can no longer use
283
- // `vnode_getNextSibling` to look at next node and instead we have to go by `vSiblings`.
284
- const idx = vSiblingsIdx + SiblingsArray . NextVNode ;
285
- return idx < vSiblings . length ? ( vSiblings [ idx ] as any ) : null ;
286
- } else {
287
- // If we don't have a `vNewNode`, than that means we just reconciled the current node.
288
- // So advance it.
289
- return vCurrent ? vnode_getNextSibling ( vCurrent ) : null ;
290
- }
275
+ // If we don't have a `vNewNode`, than that means we just reconciled the current node.
276
+ // So advance it.
277
+ return vCurrent ? vnode_getNextSibling ( vCurrent ) : null ;
291
278
}
292
279
293
280
/**
@@ -299,9 +286,6 @@ export const vnode_diff = (
299
286
*/
300
287
function advanceToNextSibling ( ) {
301
288
vCurrent = peekNextSibling ( ) ;
302
- if ( vSiblings !== null ) {
303
- vSiblingsIdx += SiblingsArray . Size ; // advance;
304
- }
305
289
}
306
290
307
291
/**
@@ -331,8 +315,6 @@ export const vnode_diff = (
331
315
stackPush ( children , descendVNode ) ;
332
316
if ( descendVNode ) {
333
317
assertDefined ( vCurrent || vNewNode , 'Expecting vCurrent to be defined.' ) ;
334
- vSiblings = null ;
335
- vSiblingsIdx = - 1 ;
336
318
vParent = vNewNode || vCurrent ! ;
337
319
vCurrent = vnode_getFirstChild ( vParent ) ;
338
320
vNewNode = null ;
@@ -343,8 +325,6 @@ export const vnode_diff = (
343
325
function ascend ( ) {
344
326
const descendVNode = stack . pop ( ) ; // boolean: descendVNode
345
327
if ( descendVNode ) {
346
- vSiblingsIdx = stack . pop ( ) ;
347
- vSiblings = stack . pop ( ) ;
348
328
vNewNode = stack . pop ( ) ;
349
329
vCurrent = stack . pop ( ) ;
350
330
vParent = stack . pop ( ) ;
@@ -359,7 +339,7 @@ export const vnode_diff = (
359
339
function stackPush ( children : JSXChildren , descendVNode : boolean ) {
360
340
stack . push ( jsxChildren , jsxIdx , jsxCount , jsxValue ) ;
361
341
if ( descendVNode ) {
362
- stack . push ( vParent , vCurrent , vNewNode , vSiblings , vSiblingsIdx ) ;
342
+ stack . push ( vParent , vCurrent , vNewNode ) ;
363
343
}
364
344
stack . push ( descendVNode ) ;
365
345
if ( Array . isArray ( children ) ) {
@@ -384,9 +364,6 @@ export const vnode_diff = (
384
364
function getInsertBefore ( ) {
385
365
if ( vNewNode ) {
386
366
return vCurrent ;
387
- } else if ( vSiblings !== null ) {
388
- const nextIdx = vSiblingsIdx + SiblingsArray . NextVNode ;
389
- return nextIdx < vSiblings . length ? ( vSiblings [ nextIdx ] as VNode ) : null ;
390
367
} else {
391
368
return peekNextSibling ( ) ;
392
369
}
@@ -751,10 +728,6 @@ export const vnode_diff = (
751
728
vCurrent = vNewNode ;
752
729
// We need to clean up the vNewNode, because we don't want to skip advance to next sibling (see `advance` function).
753
730
vNewNode = null ;
754
- // We need also to go back to the previous sibling, because we assigned previous sibling to the vCurrent.
755
- if ( vSiblings !== null ) {
756
- vSiblingsIdx -= SiblingsArray . Size ;
757
- }
758
731
}
759
732
}
760
733
// reconcile attributes
@@ -953,63 +926,21 @@ export const vnode_diff = (
953
926
}
954
927
}
955
928
956
- /**
957
- * Retrieve the child with the given key.
958
- *
959
- * By retrieving the child with the given key we are effectively removing it from the list of
960
- * future elements. This means that we can't just use `vnode_getNextSibling` to find the next
961
- * instead we have to keep track of the elements we have already seen.
962
- *
963
- * We call this materializing the elements.
964
- *
965
- * `vSiblingsIdx`:
966
- *
967
- * - -1: Not materialized
968
- * - Positive number - the index of the next element in the `vSiblings` array.
969
- *
970
- * By retrieving the child with the given key we are effectively removing it from the list (hence
971
- * we need to splice the `vSiblings` array).
972
- *
973
- * @param nodeName
974
- * @param key
975
- * @returns Array where: (see: `SiblingsArray`)
976
- *
977
- * - Idx%3 == 0 nodeName
978
- * - Idx%3 == 1 key
979
- * - Idx%3 == 2 vNode
980
- */
929
+ /** Retrieve the child with the given key. */
981
930
function retrieveChildWithKey (
982
931
nodeName : string | null ,
983
932
key : string | null
984
933
) : ElementVNode | VirtualVNode | null {
985
934
let vNodeWithKey : ElementVNode | VirtualVNode | null = null ;
986
- if ( vSiblingsIdx === - 1 ) {
987
- // it is not materialized; so materialize it.
988
- vSiblings = [ ] ;
989
- vSiblingsIdx = 0 ;
990
- let vNode = vCurrent ;
991
- while ( vNode ) {
992
- const name = vnode_isElementVNode ( vNode ) ? vnode_getElementName ( vNode ) : null ;
993
- const vKey = getKey ( vNode ) || getComponentHash ( vNode , container . $getObjectById$ ) ;
994
- if ( vNodeWithKey === null && vKey == key && name == nodeName ) {
995
- vNodeWithKey = vNode as ElementVNode | VirtualVNode ;
996
- } else {
997
- // we only add the elements which we did not find yet.
998
- vSiblings . push ( name , vKey , vNode ) ;
999
- }
1000
- vNode = vnode_getNextSibling ( vNode ) ;
1001
- }
1002
- } else {
1003
- for ( let idx = vSiblingsIdx ; idx < vSiblings ! . length ; idx += SiblingsArray . Size ) {
1004
- const name = vSiblings ! [ idx + SiblingsArray . Name ] ;
1005
- const vKey = vSiblings ! [ idx + SiblingsArray . Key ] ;
1006
- if ( vKey === key && name === nodeName ) {
1007
- vNodeWithKey = vSiblings ! [ idx + SiblingsArray . VNode ] as any ;
1008
- // remove the node from the siblings array
1009
- vSiblings ?. splice ( idx , SiblingsArray . Size ) ;
1010
- break ;
1011
- }
935
+ let vNode = vCurrent ;
936
+ while ( vNode ) {
937
+ const name = vnode_isElementVNode ( vNode ) ? vnode_getElementName ( vNode ) : null ;
938
+ const vKey = getKey ( vNode ) || getComponentHash ( vNode , container . $getObjectById$ ) ;
939
+ if ( vKey == key && name == nodeName ) {
940
+ vNodeWithKey = vNode as ElementVNode | VirtualVNode ;
941
+ break ;
1012
942
}
943
+ vNode = vnode_getNextSibling ( vNode ) ;
1013
944
}
1014
945
return vNodeWithKey ;
1015
946
}
@@ -1446,10 +1377,3 @@ function markVNodeAsDeleted(vCursor: VNode) {
1446
1377
*/
1447
1378
const HANDLER_PREFIX = ':' ;
1448
1379
let count = 0 ;
1449
- const enum SiblingsArray {
1450
- Name = 0 ,
1451
- Key = 1 ,
1452
- VNode = 2 ,
1453
- Size = 3 ,
1454
- NextVNode = Size + VNode ,
1455
- }
0 commit comments