From b5e5b5a15f8460c0effbedfd6aa39a1e594733df Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 27 Nov 2019 09:32:00 +0000 Subject: [PATCH] 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. --- src/chunker/rabin.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/chunker/rabin.js b/src/chunker/rabin.js index cb4a84b..2a53689 100644 --- a/src/chunker/rabin.js +++ b/src/chunker/rabin.js @@ -51,14 +51,11 @@ const jsRabin = () => { return async function * (source, options) { const r = await create(options.bits, options.min, options.max, options.window) const buffers = new BufferList() - let pending = [] for await (const chunk of source) { buffers.append(chunk) - pending.push(chunk) - const sizes = r.fingerprint(Buffer.concat(pending)) - pending = [] + const sizes = r.fingerprint(chunk) for (let i = 0; i < sizes.length; i++) { var size = sizes[i]