From 2136152b76540d6244689658a34043d2e0c9db65 Mon Sep 17 00:00:00 2001 From: awwit Date: Sun, 3 May 2020 17:36:34 +0300 Subject: [PATCH 1/3] feat: improved bytesToUuid func --- examples/benchmark/benchmark.js | 7 +++++- src/bytesToUuid.js | 44 ++++++++++++++++----------------- 2 files changed, 28 insertions(+), 23 deletions(-) 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..9199fad1 100644 --- a/src/bytesToUuid.js +++ b/src/bytesToUuid.js @@ -14,28 +14,28 @@ 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(''); + 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; From 149adf7a8ab002677d89bf662894250c9f19f3f3 Mon Sep 17 00:00:00 2001 From: awwit Date: Mon, 4 May 2020 17:27:47 +0300 Subject: [PATCH 2/3] style: added comment to bytesToUuid func --- src/bytesToUuid.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bytesToUuid.js b/src/bytesToUuid.js index 9199fad1..73e938e8 100644 --- a/src/bytesToUuid.js +++ b/src/bytesToUuid.js @@ -13,7 +13,9 @@ 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 + // 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 + // `toLowerCase` 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]] + From a660ec5bd39e407d9af066e75b4d2800bb2279e8 Mon Sep 17 00:00:00 2001 From: awwit Date: Mon, 4 May 2020 19:51:10 +0300 Subject: [PATCH 3/3] style: remove one line of comment --- src/bytesToUuid.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bytesToUuid.js b/src/bytesToUuid.js index 73e938e8..7e90bdb9 100644 --- a/src/bytesToUuid.js +++ b/src/bytesToUuid.js @@ -15,7 +15,6 @@ function bytesToUuid(buf, offset) { // 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 - // `toLowerCase` 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]] +