changeset 16229:d837c02aba58

support constructing a NodeInputList from a collection of NodeInterface objects
author Doug Simon <doug.simon@oracle.com>
date Wed, 25 Jun 2014 16:53:09 +0200
parents df5ac85a4813
children 5f72421928e0
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeInputList.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeInputList.java	Wed Jun 25 16:52:29 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeInputList.java	Wed Jun 25 16:53:09 2014 +0200
@@ -49,6 +49,12 @@
         this.self = self;
     }
 
+    public NodeInputList(Node self, Collection<? extends NodeInterface> elements) {
+        super(elements);
+        assert self.usages().isEmpty();
+        this.self = self;
+    }
+
     @Override
     protected void update(T oldNode, T newNode) {
         self.updateUsages(oldNode, newNode);
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Wed Jun 25 16:52:29 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Wed Jun 25 16:53:09 2014 +0200
@@ -77,6 +77,24 @@
         }
     }
 
+    protected NodeList(Collection<? extends NodeInterface> elements) {
+        if (elements == null || elements.isEmpty()) {
+            this.size = 0;
+            this.nodes = EMPTY_NODE_ARRAY;
+            this.initialSize = 0;
+        } else {
+            this.size = elements.size();
+            this.initialSize = elements.size();
+            this.nodes = new Node[elements.size()];
+            int i = 0;
+            for (NodeInterface n : elements) {
+                this.nodes[i] = n.asNode();
+                assert this.nodes[i] == null || !this.nodes[i].isDeleted();
+                i++;
+            }
+        }
+    }
+
     protected abstract void update(T oldNode, T newNode);
 
     @Override