RFR(S): 8007986: GrowableArray should implement binary search
Vitaly Davidovich
vitalyd at gmail.com
Wed Apr 15 14:52:22 UTC 2015
Hi Roland,
int mid = (int)((uint)max + min) / 2;
I'd write this as:
int mid = min + (max - min) / 2;
I'd change these:
assert(min >= 0 && (max+1) >= min, "bad bounds");assert((uint)min <=
length() && (uint)(max+1) <= length(), "incorrect bounds");
to:
assert(min >= 0 && (max - min) >= 0, "bad bounds");
assert(min <= length() && (length() - max) > 0, "incorrect bounds");
This is pedantic so please feel free to ignore if you think it's not
worthwhile.
Thanks
On Wed, Apr 15, 2015 at 6:25 AM, Roland Westrelin <
roland.westrelin at oracle.com> wrote:
> Hi Vitaly,
>
> > Just a couple of notes in passing.
> >
> > 1) may be worthwhile to compute mid in a way that avoids possible signed
> overflow? I'm guessing this class is not used with sizes that large, but
> just a precaution.
> >
> > 2) perhaps store the result of calling f() in a local to avoid calling
> it twice?
>
> Thanks for the suggestions. Here is a new webrev that take them into
> account:
>
> http://cr.openjdk.java.net/~roland/8007986/webrev.01/
>
> Roland.
>
> >
> > $.02
> >
> > sent from my phone
> >
> > On Mar 26, 2015 9:34 AM, "Roland Westrelin" <roland.westrelin at oracle.com>
> wrote:
> > http://cr.openjdk.java.net/~roland/8007986/webrev.00/
> >
> > The same binary search code on GrowableArray is used in 3 places (in the
> compilers). This moves that code in GrowableArray.
> >
> > Roland.
>
>
More information about the hotspot-dev
mailing list