Skip to content

Commit 223a6f9

Browse files
committed
[libc] remove modulo from CircularArrayRef iterator
1 parent dfcb872 commit 223a6f9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libc/benchmarks/LibcBenchmark.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,21 @@ template <typename T> class CircularArrayRef {
275275
: public std::iterator<std::input_iterator_tag, T, ssize_t> {
276276
llvm::ArrayRef<T> Array;
277277
size_t Index;
278+
size_t Offset;
278279

279280
public:
280281
explicit const_iterator(llvm::ArrayRef<T> Array, size_t Index = 0)
281-
: Array(Array), Index(Index) {}
282+
: Array(Array), Index(Index), Offset(Index % Array.size()) {}
282283
const_iterator &operator++() {
283284
++Index;
285+
++Offset;
286+
if (Offset == Array.size())
287+
Offset = 0;
284288
return *this;
285289
}
286290
bool operator==(const_iterator Other) const { return Index == Other.Index; }
287291
bool operator!=(const_iterator Other) const { return !(*this == Other); }
288-
const T &operator*() const { return Array[Index % Array.size()]; }
292+
const T &operator*() const { return Array[Offset]; }
289293
};
290294

291295
CircularArrayRef(llvm::ArrayRef<T> Array, size_t Size)

0 commit comments

Comments
 (0)