diff options
author | Harvey Harrison <[email protected]> | 2012-01-24 12:52:32 -0800 |
---|---|---|
committer | Harvey Harrison <[email protected]> | 2012-01-24 12:52:32 -0800 |
commit | 681ba61a9971570d1a00448432961ea6dad6fad9 (patch) | |
tree | f0d058282a09a0ffdb7e427ebca727a5af2d3d62 | |
parent | e44637ead1e4a02e4cf940771c1270e62c3421d7 (diff) |
j3dcore: switch the orderedBin array expansion to happen at set, rather than get time
Add early return of null for the viewIndex >= array length and only expand the
allocation when we set a non-null orderedBin.
Signed-off-by: Harvey Harrison <[email protected]>
-rw-r--r-- | src/classes/share/javax/media/j3d/OrderedGroupRetained.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/classes/share/javax/media/j3d/OrderedGroupRetained.java b/src/classes/share/javax/media/j3d/OrderedGroupRetained.java index eebfd5a..03c7da6 100644 --- a/src/classes/share/javax/media/j3d/OrderedGroupRetained.java +++ b/src/classes/share/javax/media/j3d/OrderedGroupRetained.java @@ -51,7 +51,7 @@ class OrderedGroupRetained extends GroupRetained { // used to lock the orderedBin array private final Object lockObj = new Object(); // One OrderedBin per view -OrderedBin[] orderedBin = new OrderedBin[0]; +private OrderedBin[] orderedBin = new OrderedBin[0]; // ChildCount used by renderBin to initialize the // orderedCollection in each orderedBin (per view) @@ -229,6 +229,19 @@ OrderedBin[] orderedBin = new OrderedBin[0]; void setOrderedBin(OrderedBin ob, int index) { synchronized (lockObj) { + if (index < orderedBin.length) { + orderedBin[index] = ob; + return; + } + + // If we're clearing the entry to null, just return, don't bother + // expanding the array + if (ob == null) + return; + + OrderedBin[] newList = new OrderedBin[index + 1]; + System.arraycopy(orderedBin, 0, newList, 0, orderedBin.length); + orderedBin = newList; orderedBin[index] = ob; } } @@ -236,12 +249,10 @@ void setOrderedBin(OrderedBin ob, int index) { // Get the orderedBin for this view index OrderedBin getOrderedBin(int index) { synchronized (lockObj) { - if (index >= orderedBin.length) { - OrderedBin[] newList = new OrderedBin[index + 1]; - System.arraycopy(orderedBin, 0, newList, 0, orderedBin.length); - orderedBin = newList; - } - return orderedBin[index]; + if (index >= orderedBin.length) + return null; + else + return orderedBin[index]; } } |