[Issue 20980] New: std.bigint.BigInt: special case x & 1 to avoid unnecessary allocation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 26 16:24:55 UTC 2020


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 at puremagic.com
          Reporter: n8sh.secondary at 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.

--


More information about the Digitalmars-d-bugs mailing list