perf(runtime-vapor): `children` helper (#263)

Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
Rizumu Ayaka 2024-07-29 13:54:33 +08:00 committed by GitHub
parent 0fde1e13a9
commit be332dc5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -13,9 +13,14 @@ export function template(html: string) {
/*! #__NO_SIDE_EFFECTS__ */
export function children(node: Node, ...paths: number[]): Node {
for (const idx of paths) {
for (let i = 0; i <= idx; i++) {
node = node[i === 0 ? 'firstChild' : 'nextSibling']!
}
// In various situations, select the quickest approach.
// See https://github.com/vuejs/core-vapor/pull/263
node =
idx === 0
? node.firstChild!
: idx === 1
? node.firstChild!.nextSibling!
: node.childNodes[idx]
}
return node
}