[lld] r192149 - Add comments. Early return.

Rui Ueyama ruiu at google.com
Mon Oct 7 17:43:53 PDT 2013


Author: ruiu
Date: Mon Oct  7 19:43:53 2013
New Revision: 192149

URL: http://llvm.org/viewvc/llvm-project?rev=192149&view=rev
Log:
Add comments. Early return.

Modified:
    lld/trunk/lib/Core/LinkingContext.cpp

Modified: lld/trunk/lib/Core/LinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/LinkingContext.cpp?rev=192149&r1=192148&r2=192149&view=diff
==============================================================================
--- lld/trunk/lib/Core/LinkingContext.cpp (original)
+++ lld/trunk/lib/Core/LinkingContext.cpp Mon Oct  7 19:43:53 2013
@@ -81,24 +81,30 @@ void LinkingContext::setResolverState(in
 }
 
 ErrorOr<File &> LinkingContext::nextFile() const {
+  // When nextFile() is called for the first time, _currentInputElement is not
+  // initialized. Initialize it with the first element of the input graph.
   if (_currentInputElement == nullptr) {
     ErrorOr<InputElement *> elem = inputGraph().getNextInputElement();
     if (error_code(elem) == input_graph_error::no_more_elements)
       return make_error_code(input_graph_error::no_more_files);
     _currentInputElement = *elem;
   }
-  do {
+
+  // Otherwise, try to get the next file of _currentInputElement. If the current
+  // input element points to an archive file, and there's a file left in the
+  // archive, it will succeed. If not, try to get the next file in the input
+  // graph.
+  for (;;) {
     ErrorOr<File &> nextFile = _currentInputElement->getNextFile();
-    if (error_code(nextFile) == input_graph_error::no_more_files) {
-      ErrorOr<InputElement *> elem = inputGraph().getNextInputElement();
-      if (error_code(elem) == input_graph_error::no_more_elements)
-        return make_error_code(input_graph_error::no_more_files);
-      _currentInputElement = *elem;
-    } else {
+    if (error_code(nextFile) != input_graph_error::no_more_files)
       return std::move(nextFile);
-    }
-  } while (_currentInputElement != nullptr);
-  return make_error_code(input_graph_error::no_more_files);
+
+    ErrorOr<InputElement *> elem = inputGraph().getNextInputElement();
+    if (error_code(elem) == input_graph_error::no_more_elements ||
+        *elem == nullptr)
+      return make_error_code(input_graph_error::no_more_files);
+    _currentInputElement = *elem;
+  }
 }
 
 void LinkingContext::addPasses(PassManager &pm) const {}





More information about the llvm-commits mailing list