瀏覽代碼

perf: replace $lastLogicalChild with vfor end anchor

daiwei 7 月之前
父節點
當前提交
f567f59fe7
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      packages/runtime-vapor/src/apiCreateFor.ts

+ 10 - 0
packages/runtime-vapor/src/apiCreateFor.ts

@@ -35,6 +35,7 @@ import {
 } from './dom/hydration'
 import { ForFragment, VaporFragment, findLastChild } from './fragment'
 import {
+  type ChildItem,
   insertionAnchor,
   insertionParent,
   resetInsertionState,
@@ -150,6 +151,15 @@ export const createFor = (
         if (!parentAnchor || (parentAnchor && !isComment(parentAnchor, ']'))) {
           throw new Error(`v-for fragment anchor node was not found.`)
         }
+
+        // $lastLogicalChild is the fragment start anchor; replacing it with end anchor
+        // can avoid the call to locateEndAnchor within locateChildByLogicalIndex
+        if (_insertionParent && _insertionParent!.$lastLogicalChild) {
+          ;(parentAnchor as any as ChildItem).$idx = (
+            _insertionParent!.$lastLogicalChild as ChildItem
+          ).$idx
+          _insertionParent.$lastLogicalChild = parentAnchor
+        }
       }
     } else {
       parent = parent || parentAnchor!.parentNode