[lld] r231321 - Use range-based for loops to iterate over file nodes.
Rui Ueyama
ruiu at google.com
Wed Mar 4 16:07:38 PST 2015
Author: ruiu
Date: Wed Mar 4 18:07:38 2015
New Revision: 231321
URL: http://llvm.org/viewvc/llvm-project?rev=231321&view=rev
Log:
Use range-based for loops to iterate over file nodes.
I converted them to non-range-based loops in r226883 and r226893
because at that moment File::parse() may have side effects and
may update the vector that the reference returned from
LinkingContext::nodes().
Now File::parse() is free from side effects. We can use range-based
loops again.
Modified:
lld/trunk/lib/Driver/Driver.cpp
lld/trunk/lib/Driver/WinLinkDriver.cpp
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=231321&r1=231320&r2=231321&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Wed Mar 4 18:07:38 2015
@@ -77,11 +77,8 @@ bool Driver::link(LinkingContext &contex
if (context.getNodes().empty())
return false;
- // File::parse may add items to the node list which may invalidate
- // existing iterators. Avoid using iterator to access elements.
- std::vector<std::unique_ptr<Node>> &nodes = context.getNodes();
- for (size_t i = 0; i < nodes.size(); ++i)
- if (FileNode *node = dyn_cast<FileNode>(nodes[i].get()))
+ for (std::unique_ptr<Node> &ie : context.getNodes())
+ if (FileNode *node = dyn_cast<FileNode>(ie.get()))
context.getTaskGroup().spawn([node] { node->getFile()->parse(); });
std::vector<std::unique_ptr<File>> internalFiles;
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=231321&r1=231320&r2=231321&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Wed Mar 4 18:07:38 2015
@@ -805,9 +805,8 @@ parseArgs(int argc, const char **argv, P
// graph.
static bool hasLibrary(PECOFFLinkingContext &ctx, File *file) {
StringRef path = file->path();
- std::vector<std::unique_ptr<Node>> &nodes = ctx.getNodes();
- for (size_t i = 0; i < nodes.size(); ++i)
- if (auto *f = dyn_cast<FileNode>(nodes[i].get()))
+ for (std::unique_ptr<Node> &p : ctx.getNodes())
+ if (auto *f = dyn_cast<FileNode>(p.get()))
if (f->getFile()->path() == path)
return true;
return false;
More information about the llvm-commits
mailing list