Bug 20980 – std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-26T16:24:55Z
Last change time
2020-11-11T01:10:28Z
Keywords
pull
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2020-06-26T16:24:55Z
`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.
Comment #1 by dlang-bot — 2020-06-26T17:01:40Z
@n8sh created dlang/phobos pull request #7544 "std.bigint.BigInt: special case x & 1 to avoid unnecessary allocation" fixing this issue:
- Fix Issue 20980 - std.bigint.BigInt: special case x & 1 to avoid unnecessary allocation
https://github.com/dlang/phobos/pull/7544
Comment #2 by dlang-bot — 2020-11-11T01:10:28Z
dlang/phobos pull request #7544 "std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation" was merged into master:
- 66876323c21dfbf9b187319de4e2a43c96a2a405 by Nathan Sashihara:
Fix Issue 20980 - std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation
https://github.com/dlang/phobos/pull/7544