[lld] r192418 - Replace a recursive tail call with an infinite loop.

Rui Ueyama ruiu at google.com
Thu Oct 10 21:20:30 PDT 2013


Author: ruiu
Date: Thu Oct 10 23:20:29 2013
New Revision: 192418

URL: http://llvm.org/viewvc/llvm-project?rev=192418&view=rev
Log:
Replace a recursive tail call with an infinite loop.

This eliminates _elements's size check from the loop.

Modified:
    lld/trunk/lib/Driver/InputGraph.cpp

Modified: lld/trunk/lib/Driver/InputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/InputGraph.cpp?rev=192418&r1=192417&r2=192418&view=diff
==============================================================================
--- lld/trunk/lib/Driver/InputGraph.cpp (original)
+++ lld/trunk/lib/Driver/InputGraph.cpp Thu Oct 10 23:20:29 2013
@@ -170,21 +170,24 @@ ErrorOr<File &> Group::getNextFile() {
   // If there are no elements, move on to the next input element
   if (_elements.size() == 0)
     return make_error_code(InputGraphError::no_more_files);
-  // If we have processed all the elements as part of this node
-  // check the resolver status for each input element and if the status
-  // has not changed, move onto the next file.
-  if (_nextElementIndex == _elements.size()) {
-    if (getResolveState() == Resolver::StateNoChange)
-      return make_error_code(InputGraphError::no_more_files);
-    resetNextIndex();
-  }
-  _currentElementIndex = _nextElementIndex;
-  auto file = _elements[_nextElementIndex]->getNextFile();
-  // Move on to the next element if we have finished processing all
-  // the files in the input element
-  if (error_code(file) == InputGraphError::no_more_files)
-    _nextElementIndex++;
-  else
+
+  for (;;) {
+    // If we have processed all the elements as part of this node
+    // check the resolver status for each input element and if the status
+    // has not changed, move onto the next file.
+    if (_nextElementIndex == _elements.size()) {
+      if (getResolveState() == Resolver::StateNoChange)
+        return make_error_code(InputGraphError::no_more_files);
+      resetNextIndex();
+    }
+    _currentElementIndex = _nextElementIndex;
+    auto file = _elements[_nextElementIndex]->getNextFile();
+    // Move on to the next element if we have finished processing all
+    // the files in the input element
+    if (error_code(file) == InputGraphError::no_more_files) {
+      _nextElementIndex++;
+      continue;
+    }
     return *file;
-  return getNextFile();
+  }
 }





More information about the llvm-commits mailing list