]> granicus.if.org Git - clang/commitdiff
Implement a minor optimization when loading module maps to satisfy a
authorDouglas Gregor <dgregor@apple.com>
Sat, 12 Nov 2011 00:22:19 +0000 (00:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 12 Nov 2011 00:22:19 +0000 (00:22 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144435 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/HeaderSearch.h
lib/Lex/HeaderSearch.cpp

index 98286c26f2c5c376f66e5e86b39a132772dbc3b1..092d5470911d670edefdc27b736a6713e005c6f0 100644 (file)
@@ -408,15 +408,35 @@ public:
   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.
index 3e4a1d32a0c7858c262658268fe7240804b3b14c..9d36f97335304caa006adfd18072e8d0586d6442 100644 (file)
@@ -137,22 +137,22 @@ const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName,
       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 @@ bool HeaderSearch::hasModuleMap(StringRef FileName,
       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 @@ StringRef HeaderSearch::findModuleForHeader(const FileEntry *File) {
   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 @@ bool HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir) {
       // 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;
 }