Índice de matriz de acceso de velocidad de Java versus variable temporal
Lo que es más rápido en Java. ¿Acceder directamente a un índice de matriz varias veces, o guardar el valor del índice de matriz en una nueva variable y usarlo para la siguiente compilación?
índice de acceso
<code>if ((shape.vertices[0].x >= fromX && shape.vertices[0].x <= toX) || // left side of shape in screen (shape.vertices[0].x <= fromX && shape.vertices[0].x + shape.width >= fromX) || // right side of shape in screen (shape.vertices[0].x >= fromX && shape.vertices[0].x + shape.width <= toX)) { // shape fully in screen // ... } </code>
variable temporal
<code>float x = shape.vertices[0].x; float y = shape.vertices[0].y; if ((x >= fromX && x <= toX) || // left side of shape in screen (x <= fromX && x + shape.width >= fromX) || // right side of shape in screen (x >= fromX && x + shape.width <= toX)) { // shape fully in screen // ... } </code>