Skip to content

Commit f071a86

Browse files
authored
Merge pull request #13595 from takahirox/FlattenUUID
Flatten UUID strings with .toUpperCase() to save heap memory space.
2 parents eb3aad8 + b4812b4 commit f071a86

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/math/Math.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var _Math = {
1616

1717
for ( var i = 0; i < 256; i ++ ) {
1818

19-
lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 ).toUpperCase();
19+
lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
2020

2121
}
2222

@@ -26,11 +26,14 @@ var _Math = {
2626
var d1 = Math.random() * 0xffffffff | 0;
2727
var d2 = Math.random() * 0xffffffff | 0;
2828
var d3 = Math.random() * 0xffffffff | 0;
29-
return lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
29+
var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
3030
lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
3131
lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
3232
lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
3333

34+
// .toUpperCase() here flattens concatenated strings to save heap memory space.
35+
return uuid.toUpperCase();
36+
3437
};
3538

3639
} )(),

0 commit comments

Comments
 (0)