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

Optimize from/assign str for power of 2 bases #78

Merged
merged 2 commits into from
Feb 8, 2025

Conversation

OTheDev
Copy link
Owner

@OTheDev OTheDev commented Feb 8, 2025

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.

  • Ensures that from/assign-str functions never preallocate more than one more than the number of Arbi::BASE digits actually needed to store the number the string represents. The initial calculation involving div_ceil() is great for small strings, but for very large strings, it may lead to an overallocation by hundreds or even thousands of Arbi::BASE digits. This applies for all valid bases [2, 36].
  • Fixes a bug in size_base()-type functions that used > 0 instead of != 0 when dividing an Arbi integer in-place to determine the number of base-base digits. != 0 is needed, rather than > 0 , in case the Arbi integer is negative.

@OTheDev OTheDev merged commit 296b759 into main Feb 8, 2025
11 checks passed
@OTheDev OTheDev deleted the opt_from_str_binary_bases branch February 8, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant