Indeks tablicy szybkiego dostępu Java w porównaniu ze zmienną tymczasową
Co jest szybsze w Javie. Bezpośredni wielokrotny dostęp do indeksu tablicy lub zapisanie wartości indeksu tablicy do nowej zmiennej i użycie tego do następnej kompilacji?
indeks dostępu
<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>
zmienna temp
<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>