From e742dab0d3e04161e2a34c13d6dd7e0d1507815b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 18 Oct 2023 09:12:36 +0200 Subject: [PATCH] Optimize 64-bit numberOfLeadingZeros --- lib/src/int64_native.dart | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/src/int64_native.dart b/lib/src/int64_native.dart index a7bbaed..7b0ec64 100644 --- a/lib/src/int64_native.dart +++ b/lib/src/int64_native.dart @@ -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.