www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20980] New: std.bigint.BigInt: special case x & 1 to avoid

https://issues.dlang.org/show_bug.cgi?id=20980

          Issue ID: 20980
           Summary: std.bigint.BigInt: special case x & 1 to avoid
                    unnecessary allocation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

`x & 1` is a natural way to check the low bit of `std.bigint.BigInt x` but that
allocates unlike the less natural `x.getDigit!uint(0) & 1`. Examples in Phobos
of code that does this are `std.bigint.powmod(BigInt, BigInt, BigInt)` (a PR to
fix it is pending) and `std.numeric.gcd!T(T, T)` when instantiated for
`BigInt`. Adding special handling for `x & 1` will aside from helping naive
uses also improve performance of generic templated code that operates on
arbitrary number-like types.

--
Jun 26