Skip to content

Commit

Permalink
Merge pull request #53 from reklatsmasters/patch-perf-get
Browse files Browse the repository at this point in the history
improve perfomance for BufferList#get.
  • Loading branch information
mcollina committed May 7, 2018
2 parents 27f7df8 + c7d0053 commit 02eb5a0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bl.js
Expand Up @@ -2,6 +2,7 @@ var DuplexStream = require('readable-stream/duplex')
, util = require('util')
, Buffer = require('safe-buffer').Buffer

var tempBuffer = Buffer.alloc(1)

function BufferList (callback) {
if (!(this instanceof BufferList))
Expand Down Expand Up @@ -109,7 +110,8 @@ BufferList.prototype.end = function end (chunk) {


BufferList.prototype.get = function get (index) {
return this.slice(index, index + 1)[0]
this.copy(tempBuffer, 0, index, index + 1)
return tempBuffer[0]
}


Expand Down

0 comments on commit 02eb5a0

Please sign in to comment.