-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Mutable interface for BigInts #9918
Labels
Comments
hsteoh commented on 2013-07-09T08:59:04ZIn latest git HEAD, the following works:
import std.bigint;
void main() {
BigInt x = 123;
BigInt y = 321;
x += y;
assert(x == 444);
}
Not sure what's happening under the hood, though. Is it making internal allocations? |
bearophile_hugs commented on 2013-07-09T09:57:35Z(In reply to comment #1)
> In latest git HEAD, the following works:
>
> import std.bigint;
> void main() {
> BigInt x = 123;
> BigInt y = 321;
> x += y;
> assert(x == 444);
> }
>
> Not sure what's happening under the hood, though. Is it making internal
> allocations?
That code works, but it's not about what this enhancement request is about. When you perform x+=y; the data inside x probably doesn't change. |
bearophile_hugs commented on 2013-07-09T09:58:59Z(In reply to comment #2)
> When you perform x+=y; the data inside x probably doesn't change.
I meant the original x. |
hsteoh commented on 2013-07-09T10:07:34ZYou're right, I looked at the code for BigInt, every time you do +=, it allocates a new underlying buffer. That's pretty inefficient if you're using these operations in an inner loop. |
bearophile_hugs commented on 2013-07-09T10:24:39Z(In reply to comment #4)
> You're right, I looked at the code for BigInt, every time you do +=, it
> allocates a new underlying buffer. That's pretty inefficient if you're using
> these operations in an inner loop.
On the other hand I think a mutable integer is not what most people expect, and it can cause some undesired side effects (and bugs).
That's why I suggested to introduce a specific syntax that allows you to manage bigints as mutable buffers where max performance is needed, and keep their behavour clean on default. Generally I think it's better to perform tricky optimizations only on explicit request.
Some possible alternative syntaxes:
x.mutable += y;
x.mulAcc(y);
x.mutate!"+"(y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bearophile_hugs reported this on 2011-11-25T16:52:13Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=7013
CC List
Description
The text was updated successfully, but these errors were encountered: