Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
perf: avoid unnecessary buffer copy (#40)
Browse files Browse the repository at this point in the history
The `pending` array is emptied every iteration so just pass the
file chunk directly into the rabin chunker instead.
  • Loading branch information
achingbrain authored Nov 27, 2019
1 parent d03441f commit b5e5b5a
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/chunker/rabin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b5e5b5a

Please sign in to comment.