From b20b922d9943397bcd9ac33d7bde88caa84e986e Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 16 Oct 2019 10:42:25 -0400 Subject: [PATCH] perf(v-for): use faster array population in renderList --- packages/runtime-core/src/helpers/renderList.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 5cd92e5b..0150b857 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -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! }