[clang] [clang-tools-extra] [clang][modules] Shrink the size of `Module::Headers` (PR #113395)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 25 11:00:28 PDT 2024


================
@@ -263,17 +261,36 @@ class alignas(8) Module {
     FileEntryRef Entry;
   };
 
-  /// Information about a directory name as found in the module map
-  /// file.
+private:
+  static const int NumHeaderKinds = HK_Excluded + 1;
+  // The begin index for a HeaderKind also acts the end index of HeaderKind - 1.
+  // The extra element at the end acts as the end index of the last HeaderKind.
+  unsigned HeaderKindBeginIndex[NumHeaderKinds + 1] = {};
+  SmallVector<Header, 2> HeadersStorage;
+
+public:
+  ArrayRef<Header> getAllHeaders() const { return HeadersStorage; }
+  ArrayRef<Header> getHeaders(HeaderKind HK) const {
+    assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
+    auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];
+    auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
----------------
cor3ntin wrote:

Fair enough, I'm happy with that (especially with the comment)

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


More information about the cfe-commits mailing list