lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <yo...@lucidimagination.com>
Subject Re: [VOTE] release 3.3
Date Fri, 24 Jun 2011 16:28:34 GMT
On Fri, Jun 24, 2011 at 12:14 PM, Yonik Seeley
<yonik@lucidimagination.com> wrote:
> All that needs to be done is to move the negative index check to the
> bottom (the first index<0 is not needed since we do a signed shift).
>
>  public int prevSetBit(int index) {
>    int i = index>>6;
>    if (i >= wlen) {
>      i = wlen - 1;
>    }
>    if (i < 0) return -1;
>    final int subIndex = index & 0x3f;      // index within the word
>    long word = (bits[i] << (63-subIndex));  // skip all the bits to
> the left of index

And a further minor optimization, if we assume that negative indexes
are not legal, is to move the (i<0) check inside the if (i>=wlen)
block (and just let a negative index passed by the user to cause a
natural AIOOB).

-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message