forked from OSchip/llvm-project
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. llvm-svn: 231321
This commit is contained in:
parent
ab9b179f4f
commit
5d75b6346d
|
@ -77,11 +77,8 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) {
|
|||
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;
|
||||
|
|
|
@ -805,9 +805,8 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx,
|
|||
// 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;
|
||||
|
|
Loading…
Reference in New Issue