Speed up hts_parse_decimal() handling of oversized exponents#2045
Merged
Conversation
The loop to apply exponent values could be made to run for a very long time (although not forever) if the exponent value in the number passed to the function was very large. As in both the +ve and -ve exponent cases this will eventually result in `n` becoming zero, it's possible to short-cut the rest of the loop as the final value will no longer change. (While the -ve case is obvious, the +ve one is a bit more complicated due to wrap-around. However, as each multiplication by 10 adds a factor of 2 (as 10 = 5 + 2), after at most 64 enough 2's will have accumulated in the product to make it divide exactly into 2^64 and the result will be zero.) Note that this does not try to add overflow detection, which would require more extensive changes and is left to future work. Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
491f46f to
2f71583
Compare
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.
The loop to apply exponent values could be made to run for a very long time (although not forever) if the exponent value in the number passed to the function was very large. As in both the +ve and -ve exponent cases this will eventually result in
nbecoming zero (the former through overflow), it's possible to short-cut the rest of the loop as the final value will no longer change.Note that this does not try to add overflow detection, which would require more extensive changes and is left to future work.