From 681ba61a9971570d1a00448432961ea6dad6fad9 Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Tue, 24 Jan 2012 12:52:32 -0800 Subject: 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 --- .../javax/media/j3d/OrderedGroupRetained.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/classes/share') 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]; } } -- cgit v1.2.3