perf: don't create holey arrays (#32155)
Don't use `Array` constructor with the size value (ex. `new Array(5)`) - this will create a `HOLEY_ELEMENTS` array (even if this array is filled in later on!); https://v8.dev/blog/elements-kinds https://stackoverflow.com/questions/32054170/how-to-resize-an-array PR Close #32155
This commit is contained in:

committed by
Andrew Kushnir

parent
c957dfc167
commit
64770571b2
@ -335,7 +335,7 @@ function main(args: string[]): number {
|
||||
const parts = packageName.split('/');
|
||||
// Remove the scoped package part, like @angular if present
|
||||
const nameParts = packageName.startsWith('@') ? parts.splice(1) : parts;
|
||||
const relativePath = Array(nameParts.length - 1).fill('..').join('/') || '.';
|
||||
const relativePath = newArray(nameParts.length - 1, '..').join('/') || '.';
|
||||
let basename: string;
|
||||
if (dir === 'bundles') {
|
||||
basename = nameParts.join('-') + '.umd';
|
||||
@ -435,3 +435,13 @@ export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, '')
|
||||
if (require.main === module) {
|
||||
process.exitCode = main(process.argv.slice(2));
|
||||
}
|
||||
|
||||
export function newArray<T = any>(size: number): T[];
|
||||
export function newArray<T>(size: number, value: T): T[];
|
||||
export function newArray<T>(size: number, value?: T): T[] {
|
||||
const list: T[] = [];
|
||||
for (let i = 0; i < size; i++) {
|
||||
list.push(value !);
|
||||
}
|
||||
return list;
|
||||
}
|
Reference in New Issue
Block a user