File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ import { Buffer } from 'buffer';
2
2
import { ensureBuffer } from './ensure_buffer' ;
3
3
import { deprecate , isUint8Array , randomBytes } from './parser/utils' ;
4
4
5
- // constants
6
- const PROCESS_UNIQUE = randomBytes ( 5 ) ;
7
-
8
5
// Regular expression that checks for hex value
9
6
const checkForHexRegExp = new RegExp ( '^[0-9a-fA-F]{24}$' ) ;
10
7
@@ -20,6 +17,9 @@ let i = 0;
20
17
while ( i < 10 ) decodeLookup [ 0x30 + i ] = i ++ ;
21
18
while ( i < 16 ) decodeLookup [ 0x41 - 10 + i ] = decodeLookup [ 0x61 - 10 + i ] = i ++ ;
22
19
20
+ // Unique sequence for the current process (initialized on first use)
21
+ let PROCESS_UNIQUE : Uint8Array | null = null ;
22
+
23
23
/** @public */
24
24
export interface ObjectIdLike {
25
25
id : string | Buffer ;
@@ -176,6 +176,11 @@ export class ObjectId {
176
176
// 4-byte timestamp
177
177
buffer . writeUInt32BE ( time , 0 ) ;
178
178
179
+ // set PROCESS_UNIQUE if yet not initialized
180
+ if ( PROCESS_UNIQUE === null ) {
181
+ PROCESS_UNIQUE = randomBytes ( 5 ) ;
182
+ }
183
+
179
184
// 5-byte process unique
180
185
buffer [ 4 ] = PROCESS_UNIQUE [ 0 ] ;
181
186
buffer [ 5 ] = PROCESS_UNIQUE [ 1 ] ;
You can’t perform that action at this time.
0 commit comments