mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-25 01:39:13 +08:00
35 lines
1,010 B
Text
35 lines
1,010 B
Text
/**
|
|
* Like `Array#splice`, but smarter for giant arrays.
|
|
*
|
|
* `Array#splice` takes all items to be inserted as individual argument which
|
|
* causes a stack overflow in V8 when trying to insert 100k items for instance.
|
|
*
|
|
* Otherwise, this does not return the removed items, and takes `items` as an
|
|
* array instead of rest parameters.
|
|
*
|
|
* @template {unknown} T
|
|
* @param {T[]} list
|
|
* @param {number} start
|
|
* @param {number} remove
|
|
* @param {T[]} items
|
|
* @returns {void}
|
|
*/
|
|
export function splice<T extends unknown>(
|
|
list: T[],
|
|
start: number,
|
|
remove: number,
|
|
items: T[]
|
|
): void
|
|
/**
|
|
* Append `items` (an array) at the end of `list` (another array).
|
|
* When `list` was empty, returns `items` instead.
|
|
*
|
|
* This prevents a potentially expensive operation when `list` is empty,
|
|
* and adds items in batches to prevent V8 from hanging.
|
|
*
|
|
* @template {unknown} T
|
|
* @param {T[]} list
|
|
* @param {T[]} items
|
|
* @returns {T[]}
|
|
*/
|
|
export function push<T extends unknown>(list: T[], items: T[]): T[]
|