File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -243,20 +243,13 @@ export class Long extends BSONValue {
243243 * @returns The corresponding Long value
244244 */
245245 static fromBigInt ( value : bigint , unsigned ?: boolean ) : Long {
246- const byteStr = value . toString ( 16 ) ;
247- const isNeg = byteStr [ 0 ] === '-' ;
248- const startIndex = isNeg ? 1 : 0 ;
249- const lowByteString =
250- byteStr . length - startIndex > 8
251- ? byteStr . substring ( byteStr . length - 8 , byteStr . length )
252- : isNeg
253- ? byteStr . slice ( 1 )
254- : byteStr ;
255- const highByteString =
256- byteStr . length - startIndex > 8 ? byteStr . substring ( startIndex , byteStr . length - 8 ) : 0 ;
257- return isNeg
258- ? new Long ( Number ( '0x' + lowByteString ) , Number ( '0x' + highByteString ) , unsigned ) . neg ( )
259- : new Long ( Number ( '0x' + lowByteString ) , Number ( '0x' + highByteString ) , unsigned ) ;
246+ /* eslint-disable no-bigint-usage/no-bigint-literals */
247+ const bit32Mask = 0xffffffffn ;
248+
249+ const lowBits = value & bit32Mask ;
250+ const highBits = ( value >> 32n ) & bit32Mask ;
251+ /* eslint-enable no-bigint-usage/no-bigint-literals */
252+ return new Long ( Number ( lowBits ) , Number ( highBits ) , unsigned ) ;
260253 }
261254
262255 /**
You can’t perform that action at this time.
0 commit comments