lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert engels <reng...@ix.netcom.com>
Subject Re: [jira] Created: (LUCENE-1257) Port to Java5
Date Sat, 12 Apr 2008 00:48:57 GMT
Correct.

On Apr 11, 2008, at 7:43 PM, Chris Hostetter wrote:

>
> Since i had to read robert's email about 3 times before i got what  
> he was
> saying, i'll elaborate in case anyone else is scratching their head as
> much as i was...
>
> because you could write code that looks like this...
>    for (int i = 0; i < arr.length; i++) {
>        i = getSomeNumberNotBetweenZeroAndArrLength()
>        String s = arr[i];
>    }
> ...the arr[i] lookup must do bounds checking and raise an exception if
> needed.  This is not neccessary in the "foreach" style construct where
> there is no explicit loop counter.
>
> : When iterating over an array using an indexed loop, you typically  
> need to
> : access the element, as follows:
> :
> : for(int i=0;i<100;i++) {
> : 	String s = array[i];
> : 	...
> : }
> :
> : Java performs bounds checking on the array[i] access to make sure  
> i is within
> : the limits of the array. Granted, there are optimizations the JVM  
> can do in
> : many cases using escape processing to know that i will always be  
> in the range,
> : but it is not always feasible.
> :
> : when you use
> :
> : for(String s : array) {
> : }
> :
> : the JVM uses its own internal indexer that it knows cannot be  
> outside the
> : bounds, and thus the bounds checking can be avoided.
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>


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


Mime
View raw message