@@ -253,8 +253,6 @@ class alignas(8) Module {
253253 HK_PrivateTextual,
254254 HK_Excluded
255255 };
256- static const int NumHeaderKinds = HK_Excluded + 1 ;
257-
258256 // / Information about a header directive as found in the module map
259257 // / file.
260258 struct Header {
@@ -263,17 +261,36 @@ class alignas(8) Module {
263261 FileEntryRef Entry;
264262 };
265263
266- // / Information about a directory name as found in the module map
267- // / file.
264+ private:
265+ static const int NumHeaderKinds = HK_Excluded + 1 ;
266+ // The begin index for a HeaderKind also acts the end index of HeaderKind - 1.
267+ // The extra element at the end acts as the end index of the last HeaderKind.
268+ unsigned HeaderKindBeginIndex[NumHeaderKinds + 1 ] = {};
269+ SmallVector<Header, 2 > HeadersStorage;
270+
271+ public:
272+ ArrayRef<Header> getAllHeaders () const { return HeadersStorage; }
273+ ArrayRef<Header> getHeaders (HeaderKind HK) const {
274+ assert (HK < NumHeaderKinds && " Invalid Module::HeaderKind" );
275+ auto BeginIt = HeadersStorage.begin () + HeaderKindBeginIndex[HK];
276+ auto EndIt = HeadersStorage.begin () + HeaderKindBeginIndex[HK + 1 ];
277+ return {BeginIt, EndIt};
278+ }
279+ void addHeader (HeaderKind HK, Header H) {
280+ assert (HK < NumHeaderKinds && " Invalid Module::HeaderKind" );
281+ auto EndIt = HeadersStorage.begin () + HeaderKindBeginIndex[HK + 1 ];
282+ HeadersStorage.insert (EndIt, std::move (H));
283+ for (unsigned HKI = HK + 1 ; HKI != NumHeaderKinds + 1 ; ++HKI)
284+ ++HeaderKindBeginIndex[HKI];
285+ }
286+
287+ // / Information about a directory name as found in the module map file.
268288 struct DirectoryName {
269289 std::string NameAsWritten;
270290 std::string PathRelativeToRootModuleDirectory;
271291 DirectoryEntryRef Entry;
272292 };
273293
274- // / The headers that are part of this module.
275- SmallVector<Header, 2 > Headers[5 ];
276-
277294 // / Stored information about a header directive that was found in the
278295 // / module map file but has not been resolved to a file.
279296 struct UnresolvedHeaderDirective {
0 commit comments