[cfe-commits] r144435 - in /cfe/trunk: include/clang/Lex/HeaderSearch.h lib/Lex/HeaderSearch.cpp
Douglas Gregor
dgregor at apple.com
Fri Nov 11 16:22:19 PST 2011
Author: dgregor
Date: Fri Nov 11 18:22:19 2011
New Revision: 144435
URL: http://llvm.org/viewvc/llvm-project?rev=144435&view=rev
Log:
Implement a minor optimization when loading module maps to satisfy a
module import: don't re-check for a loaded module unless we've
actually loaded a new module map file. Already-loaded module map files
aren't interesting.
Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=144435&r1=144434&r2=144435&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Nov 11 18:22:19 2011
@@ -408,15 +408,35 @@
size_t getTotalMemory() const;
private:
+ /// \brief Describes what happened when we tried to load a module map file.
+ enum LoadModuleMapResult {
+ /// \brief The module map file had already been loaded.
+ LMM_AlreadyLoaded,
+ /// \brief The module map file was loaded by this invocation.
+ LMM_NewlyLoaded,
+ /// \brief There is was directory with the given name.
+ LMM_NoDirectory,
+ /// \brief There was either no module map file or the module map file was
+ /// invalid.
+ LMM_InvalidModuleMap
+ };
+
/// \brief Try to load the module map file in the given directory.
///
- /// \returns false if the module map was loaded successfully, true otherwise.
- bool loadModuleMapFile(StringRef DirName);
+ /// \param DirName The name of the directory where we will look for a module
+ /// map file.
+ ///
+ /// \returns The result of attempting to load the module map file from the
+ /// named directory.
+ LoadModuleMapResult loadModuleMapFile(StringRef DirName);
/// \brief Try to load the module map file in the given directory.
///
- /// \returns false if the module map was loaded successfully, true otherwise.
- bool loadModuleMapFile(const DirectoryEntry *Dir);
+ /// \param Dir The directory where we will look for a module map file.
+ ///
+ /// \returns The result of attempting to load the module map file from the
+ /// named directory.
+ LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir);
/// getFileInfo - Return the HeaderFileInfo structure for the specified
/// FileEntry.
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=144435&r1=144434&r2=144435&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Nov 11 18:22:19 2011
@@ -137,22 +137,22 @@
if (!SearchDirs[Idx].isNormalDir())
continue;
- // Search for a module map in this directory, if we haven't already
- // looked there.
- if (!loadModuleMapFile(SearchDirs[Idx].getDir())) {
- // If we found a module map, look for the module again.
+ // Search for a module map file in this directory.
+ if (loadModuleMapFile(SearchDirs[Idx].getDir()) == LMM_NewlyLoaded) {
+ // We just loaded a module map file; check whether the module is
+ // available now.
Module = ModMap.findModule(ModuleName);
if (Module)
break;
}
-
+
// Search for a module map in a subdirectory with the same name as the
// module.
llvm::SmallString<128> NestedModuleMapDirName;
NestedModuleMapDirName = SearchDirs[Idx].getDir()->getName();
llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
- if (!loadModuleMapFile(NestedModuleMapDirName)) {
- // If we found a module map, look for the module again.
+ if (loadModuleMapFile(NestedModuleMapDirName) == LMM_NewlyLoaded) {
+ // If we just loaded a module map file, look for the module again.
Module = ModMap.findModule(ModuleName);
if (Module)
break;
@@ -766,13 +766,19 @@
return false;
// Try to load the module map file in this directory.
- if (!loadModuleMapFile(Dir)) {
+ switch (loadModuleMapFile(Dir)) {
+ case LMM_NewlyLoaded:
+ case LMM_AlreadyLoaded:
// Success. All of the directories we stepped through inherit this module
// map file.
for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
DirectoryHasModuleMap[FixUpDirectories[I]] = true;
return true;
+
+ case LMM_NoDirectory:
+ case LMM_InvalidModuleMap:
+ break;
}
// If we hit the top of our search, we're done.
@@ -794,18 +800,20 @@
return StringRef();
}
-bool HeaderSearch::loadModuleMapFile(StringRef DirName) {
+HeaderSearch::LoadModuleMapResult
+HeaderSearch::loadModuleMapFile(StringRef DirName) {
if (const DirectoryEntry *Dir = FileMgr.getDirectory(DirName))
return loadModuleMapFile(Dir);
- return true;
+ return LMM_NoDirectory;
}
-bool HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir) {
+HeaderSearch::LoadModuleMapResult
+HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir) {
llvm::DenseMap<const DirectoryEntry *, bool>::iterator KnownDir
= DirectoryHasModuleMap.find(Dir);
if (KnownDir != DirectoryHasModuleMap.end())
- return !KnownDir->second;
+ return KnownDir->second? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
llvm::SmallString<128> ModuleMapFileName;
ModuleMapFileName += Dir->getName();
@@ -816,12 +824,12 @@
// This directory has a module map.
DirectoryHasModuleMap[Dir] = true;
- return false;
+ return LMM_NewlyLoaded;
}
}
// No suitable module map.
DirectoryHasModuleMap[Dir] = false;
- return true;
+ return LMM_InvalidModuleMap;
}
More information about the cfe-commits
mailing list