[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:35:37 PDT 2016


timshen marked an inline comment as done.
timshen added a comment.

I also removed ++*Opt and increase it immediately at "NodeRef Next = *(*Opt)++;", so that even the early return executes, *Opt is still increased.


================
Comment at: include/llvm/ADT/DepthFirstIterator.h:110-114
@@ -109,3 +109,7 @@
 
-      for (NodeRef Next : make_range(*Opt, GT::child_end(Node))) {
+      // Notice that we use `auto &It =` here, as opposed to `auto It =` or
+      // range-based for loop, so that VisitStack.back().second actually gets
+      // updated.
+      for (auto &It = *Opt; It != GT::child_end(Node); ++It) {
+        NodeRef Next = *It;
         // Has our next sibling been visited?
----------------
dblaikie wrote:
> I /think/ it'd be more explicit & probably not need the comment if you wrote it without the reference:
> 
>   for (; *Opt != GT::child_end(Node); ++*Opt) {
>     NodeRef Next = **Opt;
>     ...
> 
> 
Done. It is more explicit.


https://reviews.llvm.org/D23649





More information about the llvm-commits mailing list