Mercurial > hg > graal-compiler
changeset 5673:d695272dd80a
split DistinctFilteredNodeIterable in it own subclass
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 21 Jun 2012 16:29:56 +0200 |
parents | 272ad540c464 |
children | b5a53a04913c |
files | graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/DistinctFilteredNodeIterable.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java |
diffstat | 2 files changed, 54 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/DistinctFilteredNodeIterable.java Thu Jun 21 16:29:56 2012 +0200 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.graph.iterators; + +import java.util.*; + +import com.oracle.graal.graph.*; + + +public class DistinctFilteredNodeIterable<T extends Node> extends FilteredNodeIterable<T> { + + public DistinctFilteredNodeIterable(NodeIterable<T> nodeIterable) { + super(nodeIterable); + } + + @Override + public DistinctFilteredNodeIterable<T> distinct() { + return this; + } + + @Override + public Iterator<T> iterator() { + return new DistinctPredicatedProxyNodeIterator<>(until, nodeIterable.iterator(), predicate); + } +}
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Thu Jun 21 16:29:14 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Thu Jun 21 16:29:56 2012 +0200 @@ -27,10 +27,9 @@ import com.oracle.graal.graph.*; public class FilteredNodeIterable<T extends Node> extends AbstractNodeIterable<T> { - private final NodeIterable<T> nodeIterable; - private NodePredicate predicate = NodePredicates.alwaysTrue(); - private NodePredicate until = NodePredicates.isNull(); - private boolean distinct; + protected final NodeIterable<T> nodeIterable; + protected NodePredicate predicate = NodePredicates.alwaysTrue(); + protected NodePredicate until = NodePredicates.isNull(); public FilteredNodeIterable(NodeIterable<T> nodeIterable) { this.nodeIterable = nodeIterable; } @@ -58,18 +57,15 @@ return this; } @Override - public FilteredNodeIterable<T> distinct() { - distinct = true; - return this; + public DistinctFilteredNodeIterable<T> distinct() { + DistinctFilteredNodeIterable<T> distinct = new DistinctFilteredNodeIterable<>(nodeIterable); + distinct.predicate = predicate; + distinct.until = until; + return distinct; } @Override public Iterator<T> iterator() { - final Iterator<T> iterator = nodeIterable.iterator(); - if (distinct) { - return new DistinctPredicatedProxyNodeIterator<>(until, iterator, predicate); - } else { - return new PredicatedProxyNodeIterator<>(until, iterator, predicate); - } + return new PredicatedProxyNodeIterator<>(until, nodeIterable.iterator(), predicate); } @SuppressWarnings("unchecked")