给定 C# 中的以下表达式,并且chunkWidth
和chunkHeight
是固定的预先计算的数字,是否可以通过预先计算部分模除法来优化表达式?
// Once assigned these guys never change
private int _chunkWidth;
private int _chunkHeight;
// This function needs to be super optimal!
SomeObject LookupObject(int row, int column) {
int index = (row % _chunkHeight) * _chunkWidth + (column % _chunkWidth);
return _objects[ index ];
}