Avoid division imposed by modulo
@@ -10,10 +10,12 @@ DenseTensorCellsIterator::next()
++_cellIdx;
if (valid()) {
for (int64_t i = (_address.size() - 1); i >= 0; --i) {
- _address[i] = (_address[i] + 1) % _type.dimensions()[i].size;
- if (_address[i] != 0) {
+ _address[i]++;
+ if (_address[i] != _type.dimensions()[i].size) {
// Outer dimension labels can only be increased when this label wraps around.
break;
+ } else {
+ _address[i] = 0;
}
}
}
