Skip to content

Commit b5e5b5a

Browse files
authored
perf: avoid unnecessary buffer copy (#40)
The `pending` array is emptied every iteration so just pass the file chunk directly into the rabin chunker instead.
1 parent d03441f commit b5e5b5a

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/chunker/rabin.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ const jsRabin = () => {
5151
return async function * (source, options) {
5252
const r = await create(options.bits, options.min, options.max, options.window)
5353
const buffers = new BufferList()
54-
let pending = []
5554

5655
for await (const chunk of source) {
5756
buffers.append(chunk)
58-
pending.push(chunk)
5957

60-
const sizes = r.fingerprint(Buffer.concat(pending))
61-
pending = []
58+
const sizes = r.fingerprint(chunk)
6259

6360
for (let i = 0; i < sizes.length; i++) {
6461
var size = sizes[i]

0 commit comments

Comments
 (0)