@@ -19,16 +19,24 @@ void ModuleSearchPathLookup::addFilesInPathToLookupTable(
1919 llvm::vfs::FileSystem *FS, StringRef SearchPath, ModuleSearchPathKind Kind,
2020 bool IsSystem, unsigned SearchPathIndex) {
2121 std::error_code Error;
22- assert (llvm::all_of (LookupTable, [&](const auto &LookupTableEntry) {
23- return llvm::none_of (LookupTableEntry.second , [&](const ModuleSearchPath &ExistingSearchPath) -> bool {
24- return ExistingSearchPath.Kind == Kind && ExistingSearchPath.Index == SearchPathIndex;
22+ auto entryAlreadyExists = [this ](ModuleSearchPathKind Kind,
23+ unsigned SearchPathIndex) -> bool {
24+ return llvm::any_of (LookupTable, [&](const auto &LookupTableEntry) {
25+ return llvm::any_of (
26+ LookupTableEntry.second , [&](ModuleSearchPathPtr ExistingSearchPath) {
27+ return ExistingSearchPath->getKind () == Kind &&
28+ ExistingSearchPath->getIndex () == SearchPathIndex;
29+ });
2530 });
26- }) && " Search path with this kind and index already exists" );
31+ };
32+ assert (!entryAlreadyExists (Kind, SearchPathIndex) &&
33+ " Search path with this kind and index already exists" );
34+ ModuleSearchPathPtr TableEntry =
35+ new ModuleSearchPath (SearchPath, Kind, IsSystem, SearchPathIndex);
2736 for (auto Dir = FS->dir_begin (SearchPath, Error);
2837 !Error && Dir != llvm::vfs::directory_iterator (); Dir.increment (Error)) {
2938 StringRef Filename = llvm::sys::path::filename (Dir->path ());
30- LookupTable[Filename].push_back (
31- {SearchPath, Kind, IsSystem, SearchPathIndex});
39+ LookupTable[Filename].push_back (TableEntry);
3240 }
3341}
3442
@@ -92,8 +100,9 @@ ModuleSearchPathLookup::searchPathsContainingFile(
92100
93101 for (auto &Filename : Filenames) {
94102 for (auto &Entry : LookupTable[Filename]) {
95- if (ResultIds.insert (std::make_pair (Entry.Kind , Entry.Index )).second ) {
96- Result.push_back (&Entry);
103+ if (ResultIds.insert (std::make_pair (Entry->getKind (), Entry->getIndex ()))
104+ .second ) {
105+ Result.push_back (Entry.get ());
97106 }
98107 }
99108 }
0 commit comments