math.big: restore and refactor str() and integer_from_string()#25154
Merged
Conversation
|
Connected to Huly®: V_0.6-23810 |
spytheman
reviewed
Aug 22, 2025
|
|
||
| const digit_array = '0123456789abcdefghijklmnopqrstuvwxyz'.bytes() | ||
| // vfmt off | ||
| const radix_options = { |
Contributor
There was a problem hiding this comment.
The keys seem to have very low cardinality, would not an array instead of a map be better? It can eliminate one hash per key lookup, and the array data will have better cache locality.
Contributor
There was a problem hiding this comment.
Although radix_options does not seem to be used in loops, so it may not matter much.
spytheman
approved these changes
Aug 22, 2025
spytheman
left a comment
Contributor
There was a problem hiding this comment.
Excellent.
Thank you 🙇🏻♂️.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
To transition to a 60-bit base for
math.big, it is necessary to return and rewrite the code forstr()andinteger_from_string(). This is also a good opportunity to additionally perform refactoring.Tests show that for multi-thousand digit numbers,
str()will now be~14xfaster, andinteger_from_string()~11xfaster.The repo already contains the necessary tests for all
radix.Patch passed tests against
gmplib.