Skip to content

Commit ca98e30

Browse files
committed
clang/Modules: Bring back optimization lost in 31e14f4
31e14f4 accidentally dropped caching of failed module loads. This brings it back by making ModuleMap::getCachedModuleLoad return an Optional.
1 parent 63c140d commit ca98e30

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clang/include/clang/Lex/ModuleMap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,11 @@ class ModuleMap {
707707
}
708708

709709
/// Return a cached module load.
710-
Module *getCachedModuleLoad(const IdentifierInfo &II) {
711-
return CachedModuleLoads.lookup(&II);
710+
llvm::Optional<Module *> getCachedModuleLoad(const IdentifierInfo &II) {
711+
auto I = CachedModuleLoads.find(&II);
712+
if (I == CachedModuleLoads.end())
713+
return None;
714+
return I->second;
712715
}
713716
};
714717

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,10 +1652,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
16521652
}
16531653

16541654
// If we don't already have information on this module, load the module now.
1655+
Module *Module = nullptr;
16551656
ModuleMap &MM = getPreprocessor().getHeaderSearchInfo().getModuleMap();
1656-
clang::Module *Module = MM.getCachedModuleLoad(*Path[0].first);
1657-
if (Module) {
1658-
// Nothing to do here, we found it.
1657+
if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) {
1658+
// Use the cached result, which may be nullptr.
1659+
Module = *MaybeModule;
16591660
} else if (ModuleName == getLangOpts().CurrentModule) {
16601661
// This is the module we're building.
16611662
Module = PP->getHeaderSearchInfo().lookupModule(

0 commit comments

Comments
 (0)