@@ -298,30 +298,30 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
298298 childVNode . _flags |= INSERT_VNODE ;
299299 }
300300 } else if ( matchingIndex !== skewedIndex ) {
301+ // When we move elements around i.e. [0, 1, 2] --> [1, 0, 2]
302+ // --> we diff 1, we find it at position 1 while our skewed index is 0 and our skew is 0
303+ // we set the skew to 1 as we found an offset.
304+ // --> we diff 0, we find it at position 0 while our skewed index is at 2 and our skew is 1
305+ // this makes us increase the skew again.
306+ // --> we diff 2, we find it at position 2 while our skewed index is at 4 and our skew is 2
307+ //
308+ // this becomes an optimization question where currently we see a 1 element offset as an insertion
309+ // or deletion i.e. we optimize for [0, 1, 2] --> [9, 0, 1, 2]
310+ // while a more than 1 offset we see as a swap.
311+ // We could probably build heuristics for having an optimized course of action here as well, but
312+ // might go at the cost of some bytes.
313+ //
314+ // If we wanted to optimize for i.e. only swaps we'd just do the last two code-branches and have
315+ // only the first item be a re-scouting and all the others fall in their skewed counter-part.
316+ // We could also further optimize for swaps
301317 if ( matchingIndex == skewedIndex - 1 ) {
302318 skew -- ;
303319 } else if ( matchingIndex == skewedIndex + 1 ) {
304320 skew ++ ;
305321 } else if ( matchingIndex > skewedIndex ) {
306- // Our matched DOM-node is further in the list of children than
307- // where it's at now.
308-
309- // When the remaining old children is bigger than the new-children
310- // minus our skewed index we know we are dealing with a shrinking list
311- // we have to increase our skew with the matchedIndex - the skewed index
312- if ( remainingOldChildren > newChildrenLength - skewedIndex ) {
313- skew += matchingIndex - skewedIndex ;
314- } else {
315- // If we have matched all the children just decrease the skew
316- skew -- ;
317- }
318- } else if ( matchingIndex < skewedIndex ) {
319- if ( matchingIndex == skewedIndex - skew ) {
320- skew -= matchingIndex - skewedIndex ;
321- } else {
322- // When our new position is in front of our old position than we increase the skew
323- skew ++ ;
324- }
322+ skew -- ;
323+ } else {
324+ skew ++ ;
325325 }
326326
327327 // Move this VNode's DOM if the original index (matchingIndex) doesn't
0 commit comments