This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
av_fetch(): use less branches.
The code that handles negative array indexes and out-of-bounds
negative indices used to require:
2 conditions for a +ve index
3 conditions for a -ve index
After this commit, for the common case where the index is in bounds,
it requires a single condition regardless of sign. For the less common
case of out-of-bounds, it requires 2 conditions.
Also, the one condition is more branch-predict friendly - it's whether
the index is in bounds or not. Previously the first test was whether
key < 0, and in code that does mixed signs, such as $a[0] + $a[-1],
branch prediction could be tricky.
It achieves this at the expense of a more complex expression for the key.