<div dir="ltr">Hi Paul,<div><br></div><div>I checked ArrayDeque, the methods that use the pattern array[x &amp; (array.length - 1)] do get matched by this patch, but there aren&#39;t dominating tests before them to totally eliminate the range check, so I wouldn&#39;t be expecting that much of a performance gain here.</div>
<div><br></div><div>e.g.</div><div><br></div><div><div>      220     /**</div><div>      221      * Inserts the specified element at the front of this deque.</div><div>      222      *</div><div>      223      * @param e the element to add</div>
<div>      224      * @throws NullPointerException if the specified element is null</div><div>      225      */</div><div>      226     public void addFirst(E e) {</div><div>      227         if (e == null)</div><div>      228             throw new NullPointerException();</div>
<div>      229         elements[head = (head - 1) &amp; (elements.length - 1)] = e;</div><div>      230         if (head == tail)</div><div>      231             doubleCapacity();</div><div>      232     }</div></div><div>
<br></div><div>There&#39;s no dominating check on elements.length, so a range check will still have to be generated in this case. Simplifying the check to (elements.length != 0) or (elements.length u&gt; 0) doesn&#39;t really buy much, because the final index is calculated and put into a register already anyway, doing the normal (index u&lt; elements.length) check before this patch should be just as fast.</div>
<div><br></div><div>Thanks,</div><div>Kris</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 13, 2014 at 1:50 PM, Paul Sandoz <span dir="ltr">&lt;<a href="mailto:paul.sandoz@oracle.com" target="_blank">paul.sandoz@oracle.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Feb 13, 2014, at 9:32 PM, John Rose &lt;<a href="mailto:john.r.rose@oracle.com">john.r.rose@oracle.com</a>&gt; wrote:<br>

&gt; You might want to look at the code for HashMap.getNode, which (I think) optimizes with your existing logic.<br>
&gt;<br>
<br>
</div>See also code in ArrayDeque.<br>
<span class="HOEnZb"><font color="#888888"><br>
Paul.<br>
<br>
</font></span></blockquote></div><br></div>