Simplify InputGraph::getNextFile. No functionality change.

llvm-svn: 208256
This commit is contained in:
Rui Ueyama 2014-05-07 22:27:12 +00:00
parent f6475bbc4b
commit 9967f49a3c
1 changed files with 11 additions and 20 deletions

View File

@ -16,29 +16,20 @@
using namespace lld;
ErrorOr<File &> InputGraph::getNextFile() {
// When getNextFile() 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 = getNextInputElement();
if (elem.getError() == InputGraphError::no_more_elements)
return make_error_code(InputGraphError::no_more_files);
_currentInputElement = *elem;
}
// 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.
// 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 (nextFile.getError() != InputGraphError::no_more_files)
return std::move(nextFile);
if (_currentInputElement) {
ErrorOr<File &> nextFile = _currentInputElement->getNextFile();
if (nextFile.getError() != InputGraphError::no_more_files)
return std::move(nextFile);
}
ErrorOr<InputElement *> elem = getNextInputElement();
if (elem.getError() == InputGraphError::no_more_elements ||
*elem == nullptr)
ErrorOr<InputElement *> elt = getNextInputElement();
if (elt.getError() == InputGraphError::no_more_elements || *elt == nullptr)
return make_error_code(InputGraphError::no_more_files);
_currentInputElement = *elem;
_currentInputElement = *elt;
}
}