[llvm] [CodeLayout][NFC] Using MergedVector to avoid extra vector allocations (PR #68724)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 11 16:39:44 PDT 2023


================
@@ -516,34 +518,62 @@ struct MergedChain {
   NodeIter End3;
 };
 
+/// A wrapper around two concatenated vectors (chains) of jumps.
+struct MergedJumpsT {
+  using JumpIter = std::vector<JumpT *>::const_iterator;
+
+  MergedJumpsT(JumpIter Begin, JumpIter End) : Begin1(Begin), End1(End) {}
+
+  template <typename F> void forEach(const F &Func) const {
+    for (auto It = Begin1; It != End1; It++)
+      Func(*It);
+    for (auto It = Begin2; It != End2; It++)
+      Func(*It);
+  }
+
+  bool empty() const { return Begin1 == End1; }
+
+  void append(JumpIter Begin, JumpIter End) {
+    assert(Begin2 == End2 && "cannot extend MergedJumpsT");
+    Begin2 = Begin;
+    End2 = End;
+  }
+
+private:
+  JumpIter Begin1;
----------------
spupyrev wrote:

Changed to `std::array<std::vector<JumpT *>*, 2>` as suggested. 
I really hope that you find the new version cleaner/simpler because I am not sure about myself :)

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


More information about the llvm-commits mailing list