Lucian Adrian Grijincu wrote:
> in apr-conv10-faster.patch you added:
> 
> static const char digits[] = "0123456789";
> *--p = digits[magnitude % 10];
> 
> Why is this faster than:
> *--p = (char) '0' + (magnitude % 10); ?
> 
> For your "faster" version, under the hood, the C compiler adds
> (magnitude % 10) to the address of digits and then copies the contents
> of the memory location represented by the sum's result into *--p.
> 
> My version just adds (magnitude % 10) to '0' and stores the result in *--p.
> 
> Am I missing something here?

nope - the proposed change is a bit more expensive.  (magnitude % 10 in
any case being the unavoidably most expensive bit.)

The only justification would be a code page where the digits aren't sequential
characters, but there is no such thing.  Note Davi's approach is sensible for
hex, and for alpha mappings which are subject to oddities such as ebcdic.


Reply via email to