mirror of https://github.com/vuejs/core.git
perf(runtime-vapor): improve traverse children
This commit is contained in:
parent
fa0ca8a5af
commit
531f4f0052
|
@ -65,14 +65,6 @@ export function remove(block: Block, parent: ParentBlock) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
|
||||||
export function children(node: Node | Node[], ...paths: number[]): Node {
|
|
||||||
for (const idx of paths) {
|
|
||||||
node = isArray(node) ? node[idx] : node.childNodes[idx]
|
|
||||||
}
|
|
||||||
return node as Node
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
export function createTextNode(val?: unknown): Text {
|
export function createTextNode(val?: unknown): Text {
|
||||||
// eslint-disable-next-line no-restricted-globals
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { isArray } from '@vue/shared'
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
export function template(str: string): () => ChildNode[] {
|
export function template(str: string): () => ChildNode[] {
|
||||||
let cached = false
|
let cached = false
|
||||||
|
@ -24,3 +26,17 @@ export function template(str: string): () => ChildNode[] {
|
||||||
function fragmentToNodes(node: DocumentFragment): ChildNode[] {
|
function fragmentToNodes(node: DocumentFragment): ChildNode[] {
|
||||||
return Array.from((node.cloneNode(true) as DocumentFragment).childNodes)
|
return Array.from((node.cloneNode(true) as DocumentFragment).childNodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
|
export function children(node: Node | Node[], ...paths: number[]): Node {
|
||||||
|
for (const idx of paths) {
|
||||||
|
if (isArray(node)) {
|
||||||
|
node = node[idx]
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i <= idx; i++) {
|
||||||
|
node = (node as Node)[i === 0 ? 'firstChild' : 'nextSibling']!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node as Node
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue