mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +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.
|
||||
*/
|
||||
export function filterInPlace<T> (array: T[], predicate: (item: T, index: number, arr: T[]) => unknown) {
|
||||
const len = array.length
|
||||
|
||||
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)) {
|
||||
const last = --array.length
|
||||
if (i < last) { array[i] = array[last]! }
|
||||
}
|
||||
for (let i = array.length; i--; i >= 0) {
|
||||
if (!predicate(array[i]!, i, array)) {
|
||||
const last = --array.length
|
||||
if (i < last) { array[i] = array[last]! }
|
||||
}
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user