[llvm-branch-commits] [libc] 223a6f9 - [libc] remove modulo from CircularArrayRef iterator

Guillaume Chatelet via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 6 04:08:45 PST 2021


Author: Guillaume Chatelet
Date: 2021-01-06T12:03:52Z
New Revision: 223a6f94c59c00733763bacc43f5b9458b4cc6f4

URL: https://github.com/llvm/llvm-project/commit/223a6f94c59c00733763bacc43f5b9458b4cc6f4
DIFF: https://github.com/llvm/llvm-project/commit/223a6f94c59c00733763bacc43f5b9458b4cc6f4.diff

LOG: [libc] remove modulo from CircularArrayRef iterator

Added: 
    

Modified: 
    libc/benchmarks/LibcBenchmark.h

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/LibcBenchmark.h b/libc/benchmarks/LibcBenchmark.h
index 6516e5f8be94..af6173ab41a0 100644
--- a/libc/benchmarks/LibcBenchmark.h
+++ b/libc/benchmarks/LibcBenchmark.h
@@ -275,17 +275,21 @@ template <typename T> class CircularArrayRef {
       : public std::iterator<std::input_iterator_tag, T, ssize_t> {
     llvm::ArrayRef<T> Array;
     size_t Index;
+    size_t Offset;
 
   public:
     explicit const_iterator(llvm::ArrayRef<T> Array, size_t Index = 0)
-        : Array(Array), Index(Index) {}
+        : Array(Array), Index(Index), Offset(Index % Array.size()) {}
     const_iterator &operator++() {
       ++Index;
+      ++Offset;
+      if (Offset == Array.size())
+        Offset = 0;
       return *this;
     }
     bool operator==(const_iterator Other) const { return Index == Other.Index; }
     bool operator!=(const_iterator Other) const { return !(*this == Other); }
-    const T &operator*() const { return Array[Index % Array.size()]; }
+    const T &operator*() const { return Array[Offset]; }
   };
 
   CircularArrayRef(llvm::ArrayRef<T> Array, size_t Size)


        


More information about the llvm-branch-commits mailing list