Skip to content

Commit be332dc

Browse files
LittleSoundsxzz
andauthored
perf(runtime-vapor): children helper (#263)
Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent 0fde1e1 commit be332dc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/runtime-vapor/src/dom/template.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export function template(html: string) {
1313
/*! #__NO_SIDE_EFFECTS__ */
1414
export function children(node: Node, ...paths: number[]): Node {
1515
for (const idx of paths) {
16-
for (let i = 0; i <= idx; i++) {
17-
node = node[i === 0 ? 'firstChild' : 'nextSibling']!
18-
}
16+
// In various situations, select the quickest approach.
17+
// See https://github.com/vuejs/core-vapor/pull/263
18+
node =
19+
idx === 0
20+
? node.firstChild!
21+
: idx === 1
22+
? node.firstChild!.nextSibling!
23+
: node.childNodes[idx]
1924
}
2025
return node
2126
}

0 commit comments

Comments
 (0)