Optimize from/assign str for power of 2 bases #78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This leads to a very significant speedup for bases 2 (
0b10
), 4 (0b100
), 8 (0b1000
), 16 (0b10000
), and 32 (0b100000
).This PR also does a few more things, which probably should have been done independently from this PR.
from
/assign
-str
functions never preallocate more than one more than the number ofArbi::BASE
digits actually needed to store the number the string represents. The initial calculation involvingdiv_ceil()
is great for small strings, but for very large strings, it may lead to an overallocation by hundreds or even thousands ofArbi::BASE
digits. This applies for all valid bases[2, 36]
.size_base()
-type functions that used> 0
instead of!= 0
when dividing anArbi
integer in-place to determine the number of base-base
digits.!= 0
is needed, rather than> 0
, in case theArbi
integer is negative.