Skip to content

Commit c47702c

Browse files
sava-smithbroofa
authored andcommitted
fix: mem issue when generating uuid (#267)
* fixed mem issues when generating uuid * updated comment on memory issue
1 parent 8561cc6 commit c47702c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/bytesToUuid.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ for (var i = 0; i < 256; ++i) {
1010
function bytesToUuid(buf, offset) {
1111
var i = offset || 0;
1212
var bth = byteToHex;
13-
return bth[buf[i++]] + bth[buf[i++]] +
14-
bth[buf[i++]] + bth[buf[i++]] + '-' +
15-
bth[buf[i++]] + bth[buf[i++]] + '-' +
16-
bth[buf[i++]] + bth[buf[i++]] + '-' +
17-
bth[buf[i++]] + bth[buf[i++]] + '-' +
18-
bth[buf[i++]] + bth[buf[i++]] +
19-
bth[buf[i++]] + bth[buf[i++]] +
20-
bth[buf[i++]] + bth[buf[i++]];
13+
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
14+
return ([bth[buf[i++]], bth[buf[i++]],
15+
bth[buf[i++]], bth[buf[i++]], '-',
16+
bth[buf[i++]], bth[buf[i++]], '-',
17+
bth[buf[i++]], bth[buf[i++]], '-',
18+
bth[buf[i++]], bth[buf[i++]], '-',
19+
bth[buf[i++]], bth[buf[i++]],
20+
bth[buf[i++]], bth[buf[i++]],
21+
bth[buf[i++]], bth[buf[i++]]]).join('');
2122
}
2223

2324
module.exports = bytesToUuid;

0 commit comments

Comments
 (0)