Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunked-splice.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict'
  2. var splice = require('../constant/splice.js')
  3. // causes a stack overflow in V8 when trying to insert 100k items for instance.
  4. function chunkedSplice(list, start, remove, items) {
  5. var end = list.length
  6. var chunkStart = 0
  7. var parameters // Make start between zero and `end` (included).
  8. if (start < 0) {
  9. start = -start > end ? 0 : end + start
  10. } else {
  11. start = start > end ? end : start
  12. }
  13. remove = remove > 0 ? remove : 0 // No need to chunk the items if there’s only a couple (10k) items.
  14. if (items.length < 10000) {
  15. parameters = Array.from(items)
  16. parameters.unshift(start, remove)
  17. splice.apply(list, parameters)
  18. } else {
  19. // Delete `remove` items starting from `start`
  20. if (remove) splice.apply(list, [start, remove]) // Insert the items in chunks to not cause stack overflows.
  21. while (chunkStart < items.length) {
  22. parameters = items.slice(chunkStart, chunkStart + 10000)
  23. parameters.unshift(start, 0)
  24. splice.apply(list, parameters)
  25. chunkStart += 10000
  26. start += 10000
  27. }
  28. }
  29. }
  30. module.exports = chunkedSplice