[llvm] [Coverage] Speed up function record iteration (PR #122050)

Hana Dusíková via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 01:11:25 PST 2025


================
@@ -765,11 +779,29 @@ class FunctionRecordIterator
   const FunctionRecord &operator*() const { return *Current; }
 
   FunctionRecordIterator &operator++() {
-    assert(Current != Records.end() && "incremented past end");
-    ++Current;
+    advanceOne();
     skipOtherFiles();
     return *this;
   }
+
+private:
+  void advanceOne() {
+    if (RecordIndices.empty()) {
+      // Iteration over all entries, advance in the list of records.
+      assert(Current != Records.end() && "incremented past end");
+      ++Current;
+    } else {
+      // Iterator over entries filtered by file name. Advance in the list of
+      // indices, and adjust the cursor in the list of records accordingly.
+      assert(CurrentIndex != RecordIndices.end() && "incremented past end");
+      ++CurrentIndex;
+      if (CurrentIndex == RecordIndices.end()) {
+        Current = Records.end();
+      } else {
+        Current = &Records[*CurrentIndex];
+      }
+    }
----------------
hanickadot wrote:

Oh the tests seem to be recently updated. Maybe it's just a problematic text.

https://github.com/llvm/llvm-project/pull/122050


More information about the llvm-commits mailing list