# HG changeset patch # User Thomas Wuerthinger # Date 1421964977 -3600 # Node ID c8fc6e2d128b0a6913e1b19e1c8b07098dbc987e # Parent 8da21b77998256ecb563197fb5ab2fc9717555da Small improvement in NodeList. diff -r 8da21b779982 -r c8fc6e2d128b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java --- 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;