Java中更快的是什么。直接多次访问数组索引,或者将数组索引的值保存到一个新变量中并将其用于后续计算?
访问索引
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
// ...
}
临时变量
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
// ...
}