var out = ''
for (var i = start; i < end; ++i) {
- out += toHex(buf[i])
+ out += hexSliceNewLookupTable[buf[i]]
}
return out
}
return str
}
-function toHex (n) {
- if (n < 16) return '0' + n.toString(16)
- return n.toString(16)
-}
-
function utf8ToBytes (string, units) {
units = units || Infinity
var codePoint
// For IE11 support
return obj !== obj // eslint-disable-line no-self-compare
}
+
+// Create lookup table for `toString('hex')`
+// See: https://github.com/feross/buffer/issues/219
+var hexSliceNewLookupTable = (function () {
+ var alphabet = '0123456789abcdef'
+ var table = new Array(256)
+ for (var i = 0; i < 16; ++i) {
+ var i16 = i * 16
+ for (var j = 0; j < 16; ++j) {
+ table[i16 + j] = alphabet[i] + alphabet[j]
+ }
+ }
+ return table
+})()