RFR 8135248: Add utility methods to check indexes and ranges

Paul Sandoz paul.sandoz at oracle.com
Mon Sep 21 19:29:19 UTC 2015


Hi Jeff,

I did wonder about that when i saw that code too. Without looking at generated machine code i do not know.

Paul.

On 21 Sep 2015, at 20:12, Jeff Hain <jeffhain at rocketmail.com> wrote:

> 
> Hi.
> 
> 
> 
> In your webrev:
> 
> + if ((length | fromIndex | size) < 0 || size > length - fromIndex)
> +   throw outOfBounds(fromIndex, size, length, oobe);
> 
> 
> 
> In Buffer.java (equivalent if adding "| size"):
>     static void checkBounds(int off, int len, int size) { // package-private
>         if ((off | len | (off + len) | (size - (off + len))) < 0)
>             throw new IndexOutOfBoundsException();
>     }
> 
> 
> 
> Maybe the second way (only one boolean check) is better for perfs?
> 
> 
> 
> -Jeff
> 




More information about the core-libs-dev mailing list