File tree Expand file tree Collapse file tree 2 files changed +2
-7
lines changed
Expand file tree Collapse file tree 2 files changed +2
-7
lines changed Original file line number Diff line number Diff line change @@ -74,10 +74,7 @@ exports.makeValueBuffer = makeValueBuffer;
7474 * @return The length of the `flexInt`
7575 */
7676function getByteCount ( firstByte ) {
77- assert_1 . default . byteUnsignedInteger ( firstByte ) ;
78- let leadingOnes ;
79- for ( leadingOnes = 0 ; firstByte & ( 1 << 7 ) ; leadingOnes ++ )
80- firstByte <<= 1 ;
77+ const leadingOnes = Math . clz32 ( ~ firstByte << 24 ) ;
8178 const bytes = NUMBER_OF_BYTES . get ( leadingOnes ) ;
8279 assert_1 . default ( bytes !== undefined , 'Invalid number of bytes' ) ;
8380 return bytes ;
Original file line number Diff line number Diff line change @@ -71,9 +71,7 @@ export function makeValueBuffer(value: number): ArrayBuffer {
7171 * @return The length of the `flexInt`
7272 */
7373export function getByteCount ( firstByte : number ) : number {
74- assert . byteUnsignedInteger ( firstByte )
75- let leadingOnes : number
76- for ( leadingOnes = 0 ; firstByte & ( 1 << 7 ) ; leadingOnes ++ ) firstByte <<= 1
74+ const leadingOnes = Math . clz32 ( ~ firstByte << 24 )
7775 const bytes = NUMBER_OF_BYTES . get ( leadingOnes )
7876 assert ( bytes !== undefined , 'Invalid number of bytes' )
7977 return bytes !
You can’t perform that action at this time.
0 commit comments