mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
refactor(utils): 7000..xx speed
This commit is contained in:
parent
57f4e5738f
commit
d2f5e535ef
@ -14,23 +14,12 @@ export function toArray<T> (value: T | T[]): T[] {
|
|||||||
* and standard filterInPlace implementations.
|
* and standard filterInPlace implementations.
|
||||||
*/
|
*/
|
||||||
export function filterInPlace<T> (array: T[], predicate: (item: T, index: number, arr: T[]) => unknown) {
|
export function filterInPlace<T> (array: T[], predicate: (item: T, index: number, arr: T[]) => unknown) {
|
||||||
const len = array.length
|
for (let i = array.length; i--; i >= 0) {
|
||||||
|
|
||||||
if (len <= 16) {
|
|
||||||
for (let i = len; i--; i >= 0) {
|
|
||||||
if (!predicate(array[i]!, i, array)) {
|
|
||||||
array.splice(i, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = len; i--; i >= 0) {
|
|
||||||
if (!predicate(array[i]!, i, array)) {
|
if (!predicate(array[i]!, i, array)) {
|
||||||
const last = --array.length
|
const last = --array.length
|
||||||
if (i < last) { array[i] = array[last]! }
|
if (i < last) { array[i] = array[last]! }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user