From 17d443f7d8cfb65a7d85803218df27a6b4ae8397 Mon Sep 17 00:00:00 2001 From: sava-smith <35050688+sava-smith@users.noreply.github.com> Date: Tue, 3 Apr 2018 08:29:48 -0700 Subject: [PATCH] fixed mem issue when generating uuid (#267) * fixed mem issues when generating uuid * updated comment on memory issue --- lib/bytesToUuid.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/bytesToUuid.js b/lib/bytesToUuid.js index 2c9a2230..847c4828 100644 --- a/lib/bytesToUuid.js +++ b/lib/bytesToUuid.js @@ -10,14 +10,15 @@ for (var i = 0; i < 256; ++i) { function bytesToUuid(buf, offset) { var i = offset || 0; var bth = byteToHex; - return bth[buf[i++]] + bth[buf[i++]] + - bth[buf[i++]] + bth[buf[i++]] + '-' + - bth[buf[i++]] + bth[buf[i++]] + '-' + - bth[buf[i++]] + bth[buf[i++]] + '-' + - bth[buf[i++]] + bth[buf[i++]] + '-' + - bth[buf[i++]] + bth[buf[i++]] + - bth[buf[i++]] + bth[buf[i++]] + - bth[buf[i++]] + bth[buf[i++]]; + // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 + return ([bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]]]).join(''); } module.exports = bytesToUuid;