append-array-in-place.ts 810 B

1234567891011121314151617181920212223
  1. const MAX_BLOCK_SIZE = 65535; // max parameter array size for use in Webkit
  2. export function appendArrayInPlace<T>(dest: T[], source: T[]) {
  3. let offset = 0;
  4. let itemsLeft = source.length;
  5. if (itemsLeft <= MAX_BLOCK_SIZE) {
  6. // eslint-disable-next-line prefer-spread -- performance
  7. dest.push.apply(dest, source);
  8. } else {
  9. while (itemsLeft > 0) {
  10. const pushCount = itemsLeft > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : itemsLeft;
  11. const subSource = source.slice(offset, offset + pushCount);
  12. // eslint-disable-next-line prefer-spread -- performance
  13. dest.push.apply(dest, subSource);
  14. itemsLeft -= pushCount;
  15. offset += pushCount;
  16. }
  17. }
  18. return dest;
  19. }
  20. export const appendArrayInPlaceCurried = <T>(dest: T[]) => (source: T[]) => appendArrayInPlace(dest, source);