perf(v-for): use faster array population in renderList

This commit is contained in:
Evan You 2019-10-16 10:42:25 -04:00
parent 32499b16e7
commit b20b922d99

View File

@ -5,14 +5,16 @@ export function renderList(
source: any,
renderItem: (value: any, key: string | number, index?: number) => VNodeChild
): VNodeChild[] {
let ret: VNodeChild[] = []
let ret: VNodeChild[]
if (isArray(source) || isString(source)) {
ret = new Array(source.length)
for (let i = 0, l = source.length; i < l; i++) {
ret.push(renderItem(source[i], i))
ret[i] = renderItem(source[i], i)
}
} else if (typeof source === 'number') {
ret = new Array(source)
for (let i = 0; i < source; i++) {
ret.push(renderItem(i + 1, i))
ret[i] = renderItem(i + 1, i)
}
} else if (isObject(source)) {
if (source[Symbol.iterator as any]) {
@ -26,5 +28,5 @@ export function renderList(
}
}
}
return ret
return ret!
}