[clang] b907ad5 - [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 21 16:23:44 PDT 2020


Author: Adrian Prantl
Date: 2020-07-21T16:23:36-07:00
New Revision: b907ad539a900279443dc8ef8816b6b5a76b1ea1

URL: https://github.com/llvm/llvm-project/commit/b907ad539a900279443dc8ef8816b6b5a76b1ea1
DIFF: https://github.com/llvm/llvm-project/commit/b907ad539a900279443dc8ef8816b6b5a76b1ea1.diff

LOG: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

Patch by Varun Gandhi!

Differential Revision: https://reviews.llvm.org/D84087

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 6b932a9a84d0..94dd21537966 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -457,8 +457,12 @@ class Module {
   /// Determine whether this module is a submodule.
   bool isSubModule() const { return Parent != nullptr; }
 
-  /// Determine whether this module is a submodule of the given other
-  /// module.
+  /// Check if this module is a (possibly transitive) submodule of \p Other.
+  ///
+  /// The 'A is a submodule of B' relation is a partial order based on the
+  /// the parent-child relationship between individual modules.
+  ///
+  /// Returns \c false if \p Other is \c nullptr.
   bool isSubModuleOf(const Module *Other) const;
 
   /// Determine whether this module is a part of a framework,

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index b3daaa3a4442..b25248de6832 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -173,14 +173,10 @@ bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
 }
 
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
-    if (This == Other)
+  for (auto *Parent = this; Parent; Parent = Parent->Parent) {
+    if (Parent == Other)
       return true;
-
-    This = This->Parent;
-  } while (This);
-
+  }
   return false;
 }
 


        


More information about the cfe-commits mailing list