[PATCH] D23649: [ADT] Change the range-based for loop in DFS to normal loop. NFC.

Tim Shen via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 19 10:33:43 PDT 2016


timshen updated this revision to Diff 68709.
timshen added a comment.

Increase the iterator right after dereference it, not at the end of the loop body.


https://reviews.llvm.org/D23649

Files:
  include/llvm/ADT/DepthFirstIterator.h

Index: include/llvm/ADT/DepthFirstIterator.h
===================================================================
--- include/llvm/ADT/DepthFirstIterator.h
+++ include/llvm/ADT/DepthFirstIterator.h
@@ -107,7 +107,11 @@
       if (!Opt)
         Opt.emplace(GT::child_begin(Node));
 
-      for (NodeRef Next : make_range(*Opt, GT::child_end(Node))) {
+      // Notice that we directly mutate *Opt here, so that
+      // VisitStack.back().second actually gets updated as the iterator
+      // increases.
+      while (*Opt != GT::child_end(Node)) {
+        NodeRef Next = *(*Opt)++;
         // Has our next sibling been visited?
         if (this->Visited.insert(Next).second) {
           // No, do it now.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23649.68709.patch
Type: text/x-patch
Size: 710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160819/036b4be8/attachment.bin>


More information about the llvm-commits mailing list