[NFC] Clean up doc comment and implementation for Module::isSubModuleOf.
authorAdrian Prantl <aprantl@apple.com>
Tue, 21 Jul 2020 23:03:56 +0000 (16:03 -0700)
committerAdrian Prantl <aprantl@apple.com>
Tue, 21 Jul 2020 23:23:36 +0000 (16:23 -0700)
Patch by Varun Gandhi!

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

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

index 6b932a9..94dd215 100644 (file)
@@ -457,8 +457,12 @@ public:
   /// 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,
index b3daaa3..b25248d 100644 (file)
@@ -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;
 }