[m-rev.] for review: speed up string to int and string to uint conversion
Zoltan Somogyi
zoltan.somogyi at runbox.com
Mon Aug 10 00:54:23 AEST 2026
On Sun, 9 Aug 2026 23:46:23 +1000, Julien Fischer <jfischer at opturion.com> wrote:
> I'll try that at some point. The other thing we can try is to use the
> initial length of the input string as a bound on the number of digits
> it could possibly contain. For sufficiently small strings we could
> have a version that omits the overflow check entirely.
Yes, that is even better, when it is applicable. Which it will be,
most of the time. Often enough that the optimization I proposed
may not be worthwhile, because it will make a difference only in
the rare cases where this one is not applicable.
> > > + % We must detect the overflow *before* it happens. Computing
> > > + % (Base * !.Int) + M and then testing the result does not work,
> >
> > ... or !.Int.
>
> I'm not sure what you mean by that.
That was supposed to be the start of another comment, which
I *thought* I deleted before I pressed "send". Ignore it.
> > I don't think CutOff and CutLimit are good names for these roles,
> > because in a sense they are BOTH limits.
> >
> > A good name for CutOff would tell readers that this is the maximum
> > that !.Int can be before the addition of a digit, and the CutLimit
> > is the max value of that digit *if* !.Int = CutOff. However, right now
> > I also cannot think of any *short* names that do that. Maybe
> > something like MaxSoFar/MaxBeforeNextDigit and MaxNextDigit?
>
> MaxIntSoFar and MaxIntLastDigit? (suitably adjusted for the negative case)
I wouldn't use either of those names, because MaxIntSoFar is
not the maximum of the values of !.Int so far, and MaxIntLastDigit is
not necessarily the last digit of any of the values of !.Int up to now.
Those two are LIMITS on !.Int and the next digit, not their PROPERTIES.
A subtle difference, but I think an important one.
Zoltan.
More information about the reviews
mailing list