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
Optimized BigInt implementation #9628
Conversation
7063387
to
adaef2b
Compare
@SethTisue I guess the CI did not like my force push. The build https://travis-ci.com/github/scala/scala/jobs/504678083 is failing because of the unused "longEncoding" method, a problem that was fixed on the force push.
Should I open a new PR and close this one? (I'm now running publishLocal on my local builds -- I guess IntelliJ doesn't have the proper Ywarn-unused flags). |
Travis likes it now. The Jenkins failures appear spurious and are now re-running. (The "combined" check only requires every commit to be green on Jenkins... whatever went wrong on Travis-CI before won't matter.) |
af6e4c8
to
2e67ec1
Compare
@SethTisue I have no idea of the cause of the failures above ( 2e67ec1 not passing, but 7cc2a07 passing where I added only a comment line). Is it due to the force-push? Anyway, the two PR contain exactly the same code, and the history here is pretty clean.
|
I don't know what happened, but Travis-CI went green when re-run. |
Let's merge this on Thursday unless there is further review feedback. |
This augments the
BigInt
class with aLong
field, so that small integers can be handled without allocating ajava.math.BigInteger
.The main motivation is to make
BigInt
a "safe integer" type with a reasonable performance profile in the case it is mainly used to storeLong
-sized integers; whereas the overhead of the introduced special case is dwarfed by thejava.math.BigInteger
machinery.To maintain binary compatibility even if
BigInt
is a final class, I added a main constructor parameter of typeLong
; that main constructor is private. The original constructor is now a secondary constructor taking a singleBigInteger
argument. Logic inside the constructor decides whether to store the value as aBigInteger
orLong
argument.This introduces a small memory overhead when
BigInt
stores aBigInteger
(but in turn,BigInteger
is a pretty mighty class which allocates an array).=====
This is a clean-up of #8932 with nicer history; see the original PR for much review discussion.