mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
refactor(utils): enhance filterInPlace documentation
This commit is contained in:
parent
d2f5e535ef
commit
3d36c99f61
@ -4,14 +4,10 @@ export function toArray<T> (value: T | T[]): T[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turbo-charged in-place array filtering. This function mutates the array.
|
* Filter out items from an array in place. This function mutates the array.
|
||||||
* Optimized for both small and large arrays using different strategies:
|
* `predicate` get through the array from the end to the start for performance.
|
||||||
* - For small arrays (<=16 items): Uses splice for better memory efficiency
|
|
||||||
* - For large arrays: Uses optimized swap-and-truncate strategy
|
|
||||||
*
|
*
|
||||||
* Processes array from end to start for maximum performance.
|
* This function should be faster than `Array.prototype.filter` on large arrays.
|
||||||
* Benchmarks show this is significantly faster than Array.prototype.filter
|
|
||||||
* 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) {
|
||||||
for (let i = array.length; i--; i >= 0) {
|
for (let i = array.length; i--; i >= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user