Which is faster in Java. Access to the index of the array several times at once, or save the value of the index of the array into a new variable and use this for later compilation?
acces index
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
// ...
}
temporary variable
float x = shape.vertices[0].x;
float y = shape.vertices[0].y;
if ((x >= fromX && x <= toX) ||
(x <= fromX && x + shape.width >= fromX) ||
(x >= fromX && x + shape.width <= toX)) {
}
source
share