Commit 385f22c
Speed up hts_parse_decimal() handling of oversized exponents
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>1 parent 942f3be commit 385f22c
2 files changed
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3923 | 3923 | | |
3924 | 3924 | | |
3925 | 3925 | | |
3926 | | - | |
3927 | | - | |
| 3926 | + | |
| 3927 | + | |
3928 | 3928 | | |
3929 | 3929 | | |
3930 | 3930 | | |
| |||
0 commit comments