Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation #7544

Merged
merged 1 commit into from Nov 11, 2020

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Jun 26, 2020

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 of this appearing in Phobos are std.bigint.powmod(BigInt, BigInt, BigInt) (PR #7525 fixes it) 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.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 26, 2020

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
20980 enhancement std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7544"

@n8sh n8sh force-pushed the issue-20980 branch 2 times, most recently from e74b588 to faa5953 Compare July 10, 2020 19:54
@n8sh
Copy link
Member Author

n8sh commented Jul 10, 2020

Generalized for non-negative built-in integers.

@n8sh n8sh changed the title std.bigint.BigInt: special case x & 1 to avoid unnecessary allocation std.bigint.BigInt: special case x & non-negative int to avoid unnecessary allocation Jul 10, 2020
@n8sh n8sh force-pushed the issue-20980 branch 3 times, most recently from 1731942 to 4f941d8 Compare July 10, 2020 20:59
@n8sh n8sh force-pushed the issue-20980 branch 2 times, most recently from 4d7d837 to 6f0637e Compare July 27, 2020 13:44
@thewilsonator
Copy link
Contributor

@n8sh please rebase it seems CI is stuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants