RFR(S): 8007986: GrowableArray should implement binary search (original) (raw)
Vitaly Davidovich vitalyd at gmail.com
Wed Apr 15 15:10:03 UTC 2015
- Previous message: RFR(S): 8007986: GrowableArray should implement binary search
- Next message: RFR: 8065585: Change ShouldNotReachHere() to never return
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Also, if you decide to take my suggestion on calculating mid, probably best to use shift instead of div - I don't think compiler will do that for you unless it proves the signed ints can't be negative.
sent from my phone On Apr 15, 2015 10:52 AM, "Vitaly Davidovich" <vitalyd at gmail.com> wrote:
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.
- Previous message: RFR(S): 8007986: GrowableArray should implement binary search
- Next message: RFR: 8065585: Change ShouldNotReachHere() to never return
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]