Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6360 from matrix-org/travis/seed-faster
Browse files Browse the repository at this point in the history
Improve arraySeed utility
  • Loading branch information
turt2live authored Jul 12, 2021
2 parents 3232926 + 4910737 commit cbce71f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/utils/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ export function arrayRescale(input: number[], newMin: number, newMax: number): n
* @returns {T[]} The array.
*/
export function arraySeed<T>(val: T, length: number): T[] {
const a: T[] = [];
for (let i = 0; i < length; i++) {
a.push(val);
}
return a;
// Size the array up front for performance, and use `fill` to let the browser
// optimize the operation better than we can with a `for` loop, if it wants.
return new Array<T>(length).fill(val);
}

/**
Expand Down

0 comments on commit cbce71f

Please sign in to comment.