Skip to content

Commit

Permalink
perf: avoid object allocation when creating strings from the underlyi…
Browse files Browse the repository at this point in the history
…ng buffer
  • Loading branch information
rklaehn authored and dignifiedquire committed Oct 18, 2018
1 parent 24079c5 commit e609298
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Decoder {
// Heap use to share the input with the parser
this._heap = new ArrayBuffer(opts.size)
this._heap8 = new Uint8Array(this._heap)
this._buffer = Buffer.from(this._heap)

this._reset()

Expand Down Expand Up @@ -354,9 +355,7 @@ class Decoder {
return ''
}

return (
Buffer.from(this._heap.slice(start, end))
).toString('utf8')
return this._buffer.toString('utf8', start, end)
}

createSimpleUnassigned (val) {
Expand Down

0 comments on commit e609298

Please sign in to comment.