Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 22175:5d2a12c9aae1
Use forEachChild instead of children iterator in Node.adoptHelper
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Fri, 18 Sep 2015 16:37:04 +0200 |
parents | dc83cc1f94f2 |
children | 0d36601f233e |
comparison
equal
deleted
inserted
replaced
22174:0bcfe8c6088f | 22175:5d2a12c9aae1 |
---|---|
203 } | 203 } |
204 newChild.adoptHelper(); | 204 newChild.adoptHelper(); |
205 } | 205 } |
206 | 206 |
207 private void adoptHelper() { | 207 private void adoptHelper() { |
208 Iterable<Node> children = this.getChildren(); | 208 NodeUtil.forEachChild(this, new NodeVisitor() { |
209 for (Node child : children) { | 209 public boolean visit(Node child) { |
210 if (child != null && child.getParent() != this) { | 210 if (child != null && child.getParent() != Node.this) { |
211 this.adoptHelper(child); | 211 Node.this.adoptHelper(child); |
212 } | 212 } |
213 } | 213 return true; |
214 } | |
215 }); | |
214 } | 216 } |
215 | 217 |
216 private void adoptUnadoptedHelper(final Node newChild) { | 218 private void adoptUnadoptedHelper(final Node newChild) { |
217 assert newChild != null; | 219 assert newChild != null; |
218 if (newChild == this) { | 220 if (newChild == this) { |
221 newChild.parent = this; | 223 newChild.parent = this; |
222 newChild.adoptUnadoptedHelper(); | 224 newChild.adoptUnadoptedHelper(); |
223 } | 225 } |
224 | 226 |
225 private void adoptUnadoptedHelper() { | 227 private void adoptUnadoptedHelper() { |
226 Iterable<Node> children = this.getChildren(); | 228 NodeUtil.forEachChild(this, new NodeVisitor() { |
227 for (Node child : children) { | 229 public boolean visit(Node child) { |
228 if (child != null && child.getParent() == null) { | 230 if (child != null && child.getParent() == null) { |
229 this.adoptUnadoptedHelper(child); | 231 Node.this.adoptUnadoptedHelper(child); |
230 } | 232 } |
231 } | 233 return true; |
234 } | |
235 }); | |
232 } | 236 } |
233 | 237 |
234 /** | 238 /** |
235 * Returns properties of this node interesting for debugging and can be overwritten by | 239 * Returns properties of this node interesting for debugging and can be overwritten by |
236 * subclasses to add their own custom properties. | 240 * subclasses to add their own custom properties. |