D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20980 - std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation
Summary: std.bigint.BigInt: special case x & non-negative int to avoid unnecessary all...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-06-26 16:24 UTC by Nathan S.
Modified: 2020-11-11 01:10 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nathan S. 2020-06-26 16:24:55 UTC
`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 Dlang Bot 2020-06-26 17:01:40 UTC
@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 Dlang Bot 2020-11-11 01:10:28 UTC
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