Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here are some suggestions, hopefully one or two will be applicable to your situation. </p> <ol> <li>Try to do only one rides.get(x) per loop. </li> <li>Cache method results in local variables as appropriate for your code.</li> </ol> <p>In some cases the compiler can optimize multiple calls to the same thing doing it just once instead, but not always for many subtle reasons. As a programmer, if you know for a fact that these should deliver the same values, then cache them in local variables.</p> <p>For example,</p> <pre><code>int sz = rides.size (); float dFP = d.getFP (); // wasn't sure of the type, so just called if float.. float dIP = d.getIP (); Corsa lastRide = rides.get ( 0 ); for ( int i = 1; i &lt; sz; i++ ) { Corsa = rides.get ( i ); float rOP = r.getOP (); if ( rOP &lt; dFP ) { float lastRideOA = lastRide.getOA (); // only get OA if rOP &lt; dFP if ( lastRideOA &gt; dIP &amp;&amp; rOP - lastRideOA &gt; DP ) { doSomething (); // maybe break; } } lastRide = r; } </code></pre> <p>These are optimizations that may not work in all cases. For example, if your <code>doSomething</code> expands the list, then you need to recompute sz, or maybe go back to doing rides.size() each iteration. These optimizations also assumes that the list is stable in that the elements don't change during the <code>get..()</code>'s. If <code>doSomething</code> makes changes to the list, then you'd need to cache less. Hopefully you get the idea. You can apply some of these techniques to the iterator form of the loop as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload