Avoid creating empty arrays
More than half of the AST nodes do not have a child. This can help reduce our memory footprint.
Change on 2017/01/31 by zgao
@@ -86,11 +86,13 @@ class ChildList<T extends TreeNode> extends AbstractList<T> {
public void accept(TreeVisitor visitor) {
// Copy all the children into an array to avoid a
// ConcurrentModificationException if the visitor removes one of the nodes.
+ if (!delegate.isEmpty()) {
ChildLink<?>[] array = delegate.toArray(new ChildLink<?>[delegate.size()]);
for (ChildLink<?> link : array) {
link.accept(visitor);
}
}
+ }
@Override
public String toString() {
