]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: replace $lastLogicalChild with vfor end anchor
authordaiwei <daiwei521@126.com>
Mon, 29 Sep 2025 14:10:24 +0000 (22:10 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 29 Sep 2025 14:10:24 +0000 (22:10 +0800)
packages/runtime-vapor/src/apiCreateFor.ts

index 51b563d97f05e32472798d2a478622cd224f0211..a6db691f760a92508fcac11a36d7b94409c6b100 100644 (file)
@@ -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