@@ -115,34 +115,30 @@ void HeaderSearch::SetSearchPaths(
115
115
llvm::DenseMap<unsigned int , unsigned int > searchDirToHSEntry) {
116
116
assert (angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size () &&
117
117
" Directory indices are unordered" );
118
- SearchDirsAlloc.DestroyAll ();
119
- SearchDirs.clear ();
120
- for (const DirectoryLookup &Dir : dirs)
121
- SearchDirs.push_back (storeSearchDir (Dir));
122
- UsedSearchDirs.clear ();
123
- SearchDirToHSEntry.clear ();
124
- for (const auto &Entry : searchDirToHSEntry)
125
- SearchDirToHSEntry.insert ({SearchDirs[Entry.first ], Entry.second });
126
-
118
+ SearchDirs = std::move (dirs);
119
+ SearchDirsUsage.assign (SearchDirs.size (), false );
127
120
AngledDirIdx = angledDirIdx;
128
121
SystemDirIdx = systemDirIdx;
129
122
NoCurDirSearch = noCurDirSearch;
123
+ SearchDirToHSEntry = std::move (searchDirToHSEntry);
130
124
// LookupFileCache.clear();
131
125
}
132
126
133
127
void HeaderSearch::AddSearchPath (const DirectoryLookup &dir, bool isAngled) {
134
128
unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
135
- SearchDirs.insert (SearchDirs.begin () + idx, storeSearchDir (dir));
129
+ SearchDirs.insert (SearchDirs.begin () + idx, dir);
130
+ SearchDirsUsage.insert (SearchDirsUsage.begin () + idx, false );
136
131
if (!isAngled)
137
132
AngledDirIdx++;
138
133
SystemDirIdx++;
139
134
}
140
135
141
136
std::vector<bool > HeaderSearch::computeUserEntryUsage () const {
142
137
std::vector<bool > UserEntryUsage (HSOpts->UserEntries .size ());
143
- for (const DirectoryLookup *SearchDir : UsedSearchDirs) {
144
- if (UsedSearchDirs.contains (SearchDir)) {
145
- auto UserEntryIdxIt = SearchDirToHSEntry.find (SearchDir);
138
+ for (unsigned I = 0 , E = SearchDirsUsage.size (); I < E; ++I) {
139
+ // Check whether this DirectoryLookup has been successfully used.
140
+ if (SearchDirsUsage[I]) {
141
+ auto UserEntryIdxIt = SearchDirToHSEntry.find (I);
146
142
// Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
147
143
if (UserEntryIdxIt != SearchDirToHSEntry.end ())
148
144
UserEntryUsage[UserEntryIdxIt->second ] = true ;
@@ -151,14 +147,6 @@ std::vector<bool> HeaderSearch::computeUserEntryUsage() const {
151
147
return UserEntryUsage;
152
148
}
153
149
154
- std::vector<bool > HeaderSearch::getSearchDirUsage () const {
155
- std::vector<bool > SearchDirUsage (SearchDirs.size ());
156
- for (unsigned I = 0 , E = SearchDirs.size (); I < E; ++I)
157
- if (UsedSearchDirs.contains (SearchDirs[I]))
158
- SearchDirUsage[I] = true ;
159
- return SearchDirUsage;
160
- }
161
-
162
150
// / CreateHeaderMap - This method returns a HeaderMap for the specified
163
151
// / FileEntry, uniquing them through the 'HeaderMaps' datastructure.
164
152
const HeaderMap *HeaderSearch::CreateHeaderMap (const FileEntry *FE) {
@@ -313,23 +301,21 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
313
301
SourceLocation ImportLoc,
314
302
bool AllowExtraModuleMapSearch) {
315
303
Module *Module = nullptr ;
316
- DirectoryLookup *SearchDir = nullptr ;
304
+ unsigned Idx ;
317
305
318
306
// Look through the various header search paths to load any available module
319
307
// maps, searching for a module map that describes this module.
320
- for (unsigned Idx = 0 ; Idx != SearchDirs.size (); ++Idx) {
321
- SearchDir = SearchDirs[Idx];
322
-
323
- if (SearchDirs[Idx]->isFramework ()) {
308
+ for (Idx = 0 ; Idx != SearchDirs.size (); ++Idx) {
309
+ if (SearchDirs[Idx].isFramework ()) {
324
310
// Search for or infer a module map for a framework. Here we use
325
311
// SearchName rather than ModuleName, to permit finding private modules
326
312
// named FooPrivate in buggy frameworks named Foo.
327
313
SmallString<128 > FrameworkDirName;
328
- FrameworkDirName += SearchDirs[Idx]-> getFrameworkDir ()->getName ();
314
+ FrameworkDirName += SearchDirs[Idx]. getFrameworkDir ()->getName ();
329
315
llvm::sys::path::append (FrameworkDirName, SearchName + " .framework" );
330
316
if (auto FrameworkDir = FileMgr.getDirectory (FrameworkDirName)) {
331
317
bool IsSystem
332
- = SearchDirs[Idx]-> getDirCharacteristic () != SrcMgr::C_User;
318
+ = SearchDirs[Idx]. getDirCharacteristic () != SrcMgr::C_User;
333
319
Module = loadFrameworkModule (ModuleName, *FrameworkDir, IsSystem);
334
320
if (Module)
335
321
break ;
@@ -339,12 +325,12 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
339
325
// FIXME: Figure out how header maps and module maps will work together.
340
326
341
327
// Only deal with normal search directories.
342
- if (!SearchDirs[Idx]-> isNormalDir ())
328
+ if (!SearchDirs[Idx]. isNormalDir ())
343
329
continue ;
344
330
345
- bool IsSystem = SearchDirs[Idx]-> isSystemHeaderDirectory ();
331
+ bool IsSystem = SearchDirs[Idx]. isSystemHeaderDirectory ();
346
332
// Search for a module map file in this directory.
347
- if (loadModuleMapFile (SearchDirs[Idx]-> getDir (), IsSystem,
333
+ if (loadModuleMapFile (SearchDirs[Idx]. getDir (), IsSystem,
348
334
/* IsFramework*/ false ) == LMM_NewlyLoaded) {
349
335
// We just loaded a module map file; check whether the module is
350
336
// available now.
@@ -356,7 +342,7 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
356
342
// Search for a module map in a subdirectory with the same name as the
357
343
// module.
358
344
SmallString<128 > NestedModuleMapDirName;
359
- NestedModuleMapDirName = SearchDirs[Idx]-> getDir ()->getName ();
345
+ NestedModuleMapDirName = SearchDirs[Idx]. getDir ()->getName ();
360
346
llvm::sys::path::append (NestedModuleMapDirName, ModuleName);
361
347
if (loadModuleMapFile (NestedModuleMapDirName, IsSystem,
362
348
/* IsFramework*/ false ) == LMM_NewlyLoaded){
@@ -368,13 +354,13 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
368
354
369
355
// If we've already performed the exhaustive search for module maps in this
370
356
// search directory, don't do it again.
371
- if (SearchDirs[Idx]-> haveSearchedAllModuleMaps ())
357
+ if (SearchDirs[Idx]. haveSearchedAllModuleMaps ())
372
358
continue ;
373
359
374
360
// Load all module maps in the immediate subdirectories of this search
375
361
// directory if ModuleName was from @import.
376
362
if (AllowExtraModuleMapSearch)
377
- loadSubdirectoryModuleMaps (* SearchDirs[Idx]);
363
+ loadSubdirectoryModuleMaps (SearchDirs[Idx]);
378
364
379
365
// Look again for the module.
380
366
Module = ModMap.findModule (ModuleName);
@@ -383,7 +369,7 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
383
369
}
384
370
385
371
if (Module)
386
- noteLookupUsage (SearchDir , ImportLoc);
372
+ noteLookupUsage (Idx , ImportLoc);
387
373
388
374
return Module;
389
375
}
@@ -509,7 +495,7 @@ Optional<FileEntryRef> DirectoryLookup::LookupFile(
509
495
// The case where the target file **exists** is handled by callee of this
510
496
// function as part of the regular logic that applies to include search paths.
511
497
// The case where the target file **does not exist** is handled here:
512
- HS.noteLookupUsage (this , IncludeLoc);
498
+ HS.noteLookupUsage (*HS. searchDirIdx (* this ) , IncludeLoc);
513
499
return None;
514
500
}
515
501
@@ -717,14 +703,13 @@ Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup(
717
703
void HeaderSearch::cacheLookupSuccess (LookupFileCacheInfo &CacheLookup,
718
704
unsigned HitIdx, SourceLocation Loc) {
719
705
CacheLookup.HitIdx = HitIdx;
720
- noteLookupUsage (SearchDirs[ HitIdx] , Loc);
706
+ noteLookupUsage (HitIdx, Loc);
721
707
}
722
708
723
- void HeaderSearch::noteLookupUsage (const DirectoryLookup *SearchDir,
724
- SourceLocation Loc) {
725
- UsedSearchDirs.insert (SearchDir);
709
+ void HeaderSearch::noteLookupUsage (unsigned HitIdx, SourceLocation Loc) {
710
+ SearchDirsUsage[HitIdx] = true ;
726
711
727
- auto UserEntryIdxIt = SearchDirToHSEntry.find (SearchDir );
712
+ auto UserEntryIdxIt = SearchDirToHSEntry.find (HitIdx );
728
713
if (UserEntryIdxIt != SearchDirToHSEntry.end ())
729
714
Diags.Report (Loc, diag::remark_pp_search_path_usage)
730
715
<< HSOpts->UserEntries [UserEntryIdxIt->second ].Path ;
@@ -978,7 +963,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
978
963
// If this is a #include_next request, start searching after the directory the
979
964
// file was found in.
980
965
if (FromDir)
981
- i = std::distance (SearchDirs. begin (), llvm::find (SearchDirs, FromDir)) ;
966
+ i = FromDir-&SearchDirs[ 0 ] ;
982
967
983
968
// Cache all of the lookups performed by this method. Many headers are
984
969
// multiply included, and the "pragma once" optimization prevents them from
@@ -1011,7 +996,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
1011
996
bool InUserSpecifiedSystemFramework = false ;
1012
997
bool IsInHeaderMap = false ;
1013
998
bool IsFrameworkFoundInDir = false ;
1014
- Optional<FileEntryRef> File = SearchDirs[i]-> LookupFile (
999
+ Optional<FileEntryRef> File = SearchDirs[i]. LookupFile (
1015
1000
Filename, *this , IncludeLoc, SearchPath, RelativePath, RequestingModule,
1016
1001
SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
1017
1002
IsInHeaderMap, MappedName);
@@ -1033,7 +1018,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
1033
1018
if (!File)
1034
1019
continue ;
1035
1020
1036
- CurDir = SearchDirs[i];
1021
+ CurDir = & SearchDirs[i];
1037
1022
1038
1023
// This file is a system header or C++ unfriendly if the dir is.
1039
1024
HeaderFileInfo &HFI = getFileInfo (&File->getFileEntry ());
@@ -1455,6 +1440,13 @@ size_t HeaderSearch::getTotalMemory() const {
1455
1440
+ FrameworkMap.getAllocator ().getTotalMemory ();
1456
1441
}
1457
1442
1443
+ Optional<unsigned > HeaderSearch::searchDirIdx (const DirectoryLookup &DL) const {
1444
+ for (unsigned I = 0 ; I < SearchDirs.size (); ++I)
1445
+ if (&SearchDirs[I] == &DL)
1446
+ return I;
1447
+ return None;
1448
+ }
1449
+
1458
1450
StringRef HeaderSearch::getUniqueFrameworkName (StringRef Framework) {
1459
1451
return FrameworkNames.insert (Framework).first ->first ();
1460
1452
}
@@ -1782,11 +1774,11 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1782
1774
if (HSOpts->ImplicitModuleMaps ) {
1783
1775
// Load module maps for each of the header search directories.
1784
1776
for (unsigned Idx = 0 , N = SearchDirs.size (); Idx != N; ++Idx) {
1785
- bool IsSystem = SearchDirs[Idx]-> isSystemHeaderDirectory ();
1786
- if (SearchDirs[Idx]-> isFramework ()) {
1777
+ bool IsSystem = SearchDirs[Idx]. isSystemHeaderDirectory ();
1778
+ if (SearchDirs[Idx]. isFramework ()) {
1787
1779
std::error_code EC;
1788
1780
SmallString<128 > DirNative;
1789
- llvm::sys::path::native (SearchDirs[Idx]-> getFrameworkDir ()->getName (),
1781
+ llvm::sys::path::native (SearchDirs[Idx]. getFrameworkDir ()->getName (),
1790
1782
DirNative);
1791
1783
1792
1784
// Search each of the ".framework" directories to load them as modules.
@@ -1810,16 +1802,16 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1810
1802
}
1811
1803
1812
1804
// FIXME: Deal with header maps.
1813
- if (SearchDirs[Idx]-> isHeaderMap ())
1805
+ if (SearchDirs[Idx]. isHeaderMap ())
1814
1806
continue ;
1815
1807
1816
1808
// Try to load a module map file for the search directory.
1817
- loadModuleMapFile (SearchDirs[Idx]-> getDir (), IsSystem,
1809
+ loadModuleMapFile (SearchDirs[Idx]. getDir (), IsSystem,
1818
1810
/* IsFramework*/ false );
1819
1811
1820
1812
// Try to load module map files for immediate subdirectories of this
1821
1813
// search directory.
1822
- loadSubdirectoryModuleMaps (* SearchDirs[Idx]);
1814
+ loadSubdirectoryModuleMaps (SearchDirs[Idx]);
1823
1815
}
1824
1816
}
1825
1817
@@ -1835,13 +1827,14 @@ void HeaderSearch::loadTopLevelSystemModules() {
1835
1827
// Load module maps for each of the header search directories.
1836
1828
for (unsigned Idx = 0 , N = SearchDirs.size (); Idx != N; ++Idx) {
1837
1829
// We only care about normal header directories.
1838
- if (!SearchDirs[Idx]-> isNormalDir ())
1830
+ if (!SearchDirs[Idx]. isNormalDir ()) {
1839
1831
continue ;
1832
+ }
1840
1833
1841
1834
// Try to load a module map file for the search directory.
1842
- loadModuleMapFile (SearchDirs[Idx]-> getDir (),
1843
- SearchDirs[Idx]-> isSystemHeaderDirectory (),
1844
- SearchDirs[Idx]-> isFramework ());
1835
+ loadModuleMapFile (SearchDirs[Idx]. getDir (),
1836
+ SearchDirs[Idx]. isSystemHeaderDirectory (),
1837
+ SearchDirs[Idx]. isFramework ());
1845
1838
}
1846
1839
}
1847
1840
@@ -1939,15 +1932,15 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
1939
1932
1940
1933
bool BestPrefixIsFramework = false ;
1941
1934
for (unsigned I = 0 ; I != SearchDirs.size (); ++I) {
1942
- if (SearchDirs[I]-> isNormalDir ()) {
1943
- StringRef Dir = SearchDirs[I]-> getDir ()->getName ();
1935
+ if (SearchDirs[I]. isNormalDir ()) {
1936
+ StringRef Dir = SearchDirs[I]. getDir ()->getName ();
1944
1937
if (CheckDir (Dir)) {
1945
1938
if (IsSystem)
1946
1939
*IsSystem = BestPrefixLength ? I >= SystemDirIdx : false ;
1947
1940
BestPrefixIsFramework = false ;
1948
1941
}
1949
- } else if (SearchDirs[I]-> isFramework ()) {
1950
- StringRef Dir = SearchDirs[I]-> getFrameworkDir ()->getName ();
1942
+ } else if (SearchDirs[I]. isFramework ()) {
1943
+ StringRef Dir = SearchDirs[I]. getFrameworkDir ()->getName ();
1951
1944
if (CheckDir (Dir)) {
1952
1945
if (IsSystem)
1953
1946
*IsSystem = BestPrefixLength ? I >= SystemDirIdx : false ;
@@ -1968,11 +1961,11 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
1968
1961
// key from header name is user prefered name for the include file.
1969
1962
StringRef Filename = File.drop_front (BestPrefixLength);
1970
1963
for (unsigned I = 0 ; I != SearchDirs.size (); ++I) {
1971
- if (!SearchDirs[I]-> isHeaderMap ())
1964
+ if (!SearchDirs[I]. isHeaderMap ())
1972
1965
continue ;
1973
1966
1974
1967
StringRef SpelledFilename =
1975
- SearchDirs[I]-> getHeaderMap ()->reverseLookupFilename (Filename);
1968
+ SearchDirs[I]. getHeaderMap ()->reverseLookupFilename (Filename);
1976
1969
if (!SpelledFilename.empty ()) {
1977
1970
Filename = SpelledFilename;
1978
1971
BestPrefixIsFramework = false ;
0 commit comments