diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index c83a02dd..b62b16ae 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -9,7 +9,12 @@ const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid console.log('Starting. Tests take ~1 minute to run ...'); const array = new Array(16); -const suite = new Benchmark.Suite(); + +const suite = new Benchmark.Suite({ + onError(event) { + console.error(event.target.error); + }, +}); suite .add('uuidv1()', function () { diff --git a/src/bytesToUuid.js b/src/bytesToUuid.js index bb26d28a..7e90bdb9 100644 --- a/src/bytesToUuid.js +++ b/src/bytesToUuid.js @@ -13,29 +13,30 @@ function bytesToUuid(buf, offset) { const bth = byteToHex; - // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 - return [ - bth[buf[i + 0]], - bth[buf[i + 1]], - bth[buf[i + 2]], - bth[buf[i + 3]], - '-', - bth[buf[i + 4]], - bth[buf[i + 5]], - '-', - bth[buf[i + 6]], - bth[buf[i + 7]], - '-', - bth[buf[i + 8]], - bth[buf[i + 9]], - '-', - bth[buf[i + 10]], - bth[buf[i + 11]], - bth[buf[i + 12]], - bth[buf[i + 13]], - bth[buf[i + 14]], - bth[buf[i + 15]], - ].join(''); + // Note: Be careful editing this code! It's been tuned for performance + // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 + return ( + bth[buf[i + 0]] + + bth[buf[i + 1]] + + bth[buf[i + 2]] + + bth[buf[i + 3]] + + '-' + + bth[buf[i + 4]] + + bth[buf[i + 5]] + + '-' + + bth[buf[i + 6]] + + bth[buf[i + 7]] + + '-' + + bth[buf[i + 8]] + + bth[buf[i + 9]] + + '-' + + bth[buf[i + 10]] + + bth[buf[i + 11]] + + bth[buf[i + 12]] + + bth[buf[i + 13]] + + bth[buf[i + 14]] + + bth[buf[i + 15]] + ).toLowerCase(); } export default bytesToUuid;