Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Optimize 64-bit numberOfLeadingZeros
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Oct 18, 2023
1 parent 66768ce commit e742dab
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions lib/src/int64_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,7 @@ class Int64 implements IntX {
/// Returns the number of leading zeros in this [Int64] as an [int]
/// between 0 and 64.
@override
int numberOfLeadingZeros() {
final high = _i >>> 32;
final highLeadingZeroes = u.numberOfLeadingZeros(high);
if (highLeadingZeroes == 32) {
final low = _i & 0xFFFFFFFF;
final lowLeadingZeroes = u.numberOfLeadingZeros(low);
return 32 + lowLeadingZeroes;
}
return highLeadingZeroes;
}
int numberOfLeadingZeros() => _i < 0 ? 0 : (64 - _i.bitLength);

/// Returns the number of trailing zeros in this [Int64] as an [int] between
/// 0 and 64.
Expand Down

0 comments on commit e742dab

Please sign in to comment.