From a7dcc6a48c0138d5af200ae1bf2698a3aada40dd Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Sun, 20 Oct 2024 23:22:59 +0300 Subject: [PATCH] perf: use fixed-length array for known result sizes --- packages/nuxt/src/core/app.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index f0426b62a3..a4a6ff3891 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -251,14 +251,14 @@ function resolvePaths> (items: Item[], key: { [ const IS_TSX = /\.[jt]sx$/ export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) { - const _plugins: Array> = [] - for (const plugin of plugins) { + const _plugins: Array> = new Array(plugins.length) + for (let i = 0; i < plugins.length; i++) { try { const code = plugin.src in nuxt.vfs ? nuxt.vfs[plugin.src]! : await fsp.readFile(plugin.src!, 'utf-8') - _plugins.push({ + _plugins[i] = { ...await extractMetadata(code, IS_TSX.test(plugin.src) ? 'tsx' : 'ts'), ...plugin, - }) + } } catch (e) { const relativePluginSrc = relative(nuxt.options.rootDir, plugin.src) if ((e as Error).message === 'Invalid plugin metadata') { @@ -266,7 +266,7 @@ export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) { } else { logger.warn(`Failed to parse static properties from plugin \`${relativePluginSrc}\`.`, e) } - _plugins.push(plugin) + _plugins[i] = plugins[i] } }