|[16 earlier articles]|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (Stefan Monnier) (2000-05-01)|
|Re: eliminating array bounds checking overhead email@example.com (2000-05-01)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (Mark Williams) (2000-05-04)|
|Re: eliminating array bounds checking overhead email@example.com (Robert A Duff) (2000-05-04)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (Paul Evans) (2000-05-04)|
|Re: eliminating array bounds checking overhead email@example.com (Josef Sveningsson) (2000-05-12)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (Matt Timmermans) (2000-05-12)|
|From:||"Matt Timmermans" <email@example.com>|
|Date:||12 May 2000 22:34:04 -0400|
|X-MimeOLE:||Produced By Microsoft MimeOLE V4.72.3110.3|
Norman Ramsey wrote in message 00-04-208...
>Bonus trick, which I learned from Andrew Appel:
> ((unsigned)(i-(lo+1)) < hi)
>Beware fencepost errors.
Uh oh... I think your programs are exploding.
To replace (i > lo && i < hi), you need ((unsigned)(i-(lo+1)) <
Note to the original poster: This isn't too useful as written, but that's
because of the way you phrased your check. When this trick is used, you
store the first valid index (lo) and the number of valid indeces (size), so
your check would be (i>=lo && i<(lo+size)). The trick is then
((unsigned)(i-lo)) < size), which is certainly faster than the two
Often, lo is known to be zero, because you are indexing from a pointer to
the first element in the array, and so the quick check is just (unsigned)lo
< size, and the cast is free.
Return to the
Search the comp.compilers archives again.