buffer icon indicating copy to clipboard operation
buffer copied to clipboard

BugFix: NodeJS Buffer behavior fix + performance increase

Open junderw opened this issue 2 years ago • 1 comments

In NodeJS, the behavior of Buffer.from(x, 'hex') differed slightly on its handling of bad hex parsing.

My fix also increased performance. I tried parsing a hex string '7c'.repeat(5e7) and it went from 2.8 s to ~800ms.

// node
> Buffer.from('abc def01','hex')
<Buffer ab>
// this library
> require('./index.js').Buffer.from('abc def01','hex')
<Buffer ab 0c de f0>

junderw avatar Oct 16 '21 11:10 junderw

Note: This new implementation also mimics the code for NodeJS hex parser used in the from(x, 'hex') portion.

https://github.com/nodejs/node/blob/v14.18.1/src/string_bytes.cc#L246-L261

junderw avatar Oct 16 '21 12:10 junderw