]> granicus.if.org Git - clang/commitdiff
Simplify computation of visible module set.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Nov 2013 02:19:14 +0000 (02:19 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Nov 2013 02:19:14 +0000 (02:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193850 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Module.h
lib/Basic/Module.cpp

index 3d8b75b471f6089383882d6cf679781ea253f2ec..e8d774e1eb54ba3d1daf2ff143c6f4ca103fa144 100644 (file)
@@ -403,10 +403,10 @@ public:
   submodule_iterator submodule_end()   { return SubModules.end(); }
   submodule_const_iterator submodule_end() const { return SubModules.end(); }
 
-  /// \brief Returns the exported modules based on the wildcard restrictions.
+  /// \brief Appends this module's list of exported modules to \p Exported.
   ///
-  /// This returns a subset of immediately imported modules (the ones that are
-  /// exported), not the complete set of exported modules.
+  /// This provides a subset of immediately imported modules (the ones that are
+  /// directly exported), not the complete set of exported modules.
   void getExportedModules(SmallVectorImpl<Module *> &Exported) const;
 
   static StringRef getModuleInputBufferName() {
index ccf7077d6fb88e60068718ef4892b592f46e566f..4818e8d173cc20bdc4476d837ec0017682db91e2 100644 (file)
@@ -253,22 +253,13 @@ void Module::buildVisibleModulesCache() const {
   VisibleModulesCache.insert(this);
 
   // Every imported module is visible.
-  // Every module exported by an imported module is visible.
-  llvm::SmallPtrSet<Module *, 4> Visited;
-  llvm::SmallVector<Module *, 4> Exports;
-  SmallVector<Module *, 4> Stack(Imports.begin(), Imports.end());
+  SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end());
   while (!Stack.empty()) {
     Module *CurrModule = Stack.pop_back_val();
-    VisibleModulesCache.insert(CurrModule);
-
-    CurrModule->getExportedModules(Exports);
-    for (SmallVectorImpl<Module *>::iterator I = Exports.begin(),
-                                             E = Exports.end();
-         I != E; ++I) {
-      Module *Exported = *I;
-      if (Visited.insert(Exported))
-        Stack.push_back(Exported);
-    }
+
+    // Every module transitively exported by an imported module is visible.
+    if (VisibleModulesCache.insert(CurrModule).second)
+      CurrModule->getExportedModules(Stack);
   }
 }