changeset 18928:c8fc6e2d128b

Small improvement in NodeList.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 22 Jan 2015 23:16:17 +0100
parents 8da21b779982
children 8f2fb6bec986
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Thu Jan 22 21:53:06 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Thu Jan 22 23:16:17 2015 +0100
@@ -139,7 +139,10 @@
         assert node == null || !node.isDeleted();
         self.incModCount();
         incModCount();
-        if (size == nodes.length) {
+        int length = nodes.length;
+        if (length == 0) {
+            nodes = new Node[2];
+        } else if (size == length) {
             nodes = Arrays.copyOf(nodes, nodes.length * 2 + 1);
         }
         nodes[size++] = node;
@@ -150,8 +153,13 @@
     @Override
     @SuppressWarnings("unchecked")
     public T get(int index) {
+        assert assertInRange(index);
+        return (T) nodes[index];
+    }
+
+    private boolean assertInRange(int index) {
         assert index < size() : index + " < " + size();
-        return (T) nodes[index];
+        return true;
     }
 
     public T last() {
@@ -163,7 +171,7 @@
     public T set(int index, Node node) {
         incModCount();
         T oldValue = (T) nodes[index];
-        assert index < size();
+        assert assertInRange(index);
         update((T) nodes[index], (T) node);
         nodes[index] = node;
         return oldValue;