[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:10:17 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 it does, but it can be unrelated. It occurred to me as I looked at `getImpreciseRecordIndicesForFilename` and there was this comment:

```
/// Look up the indices for function records which are at least partially
/// defined in the specified file. This is guaranteed to return a superset of
/// such records: extra records not in the file may be included if there is
/// a hash collision on the filename. Clients must be robust to collisions.
```

which somehow triggered my response

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


More information about the llvm-commits mailing list