OSDN Git Service

Fixed array[] constructors backing array size.
authorNathanSweet <nathan.sweet@gmail.com>
Sun, 15 Sep 2013 13:37:38 +0000 (15:37 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Sun, 15 Sep 2013 13:37:38 +0000 (15:37 +0200)
gdx/src/com/badlogic/gdx/utils/Array.java
gdx/src/com/badlogic/gdx/utils/ArrayMap.java
gdx/src/com/badlogic/gdx/utils/BooleanArray.java
gdx/src/com/badlogic/gdx/utils/CharArray.java
gdx/src/com/badlogic/gdx/utils/FloatArray.java
gdx/src/com/badlogic/gdx/utils/IntArray.java
gdx/src/com/badlogic/gdx/utils/LongArray.java
gdx/src/com/badlogic/gdx/utils/ShortArray.java

index 22c4149..d878f30 100644 (file)
@@ -90,7 +90,7 @@ public class Array<T> implements Iterable<T> {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public Array (boolean ordered, T[] array, int start, int count) {\r
-               this(ordered, array.length, (Class)array.getClass().getComponentType());\r
+               this(ordered, count, (Class)array.getClass().getComponentType());\r
                size = count;\r
                System.arraycopy(array, 0, items, 0, size);\r
        }\r
@@ -302,6 +302,7 @@ public class Array<T> implements Iterable<T> {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index 721ee33..ee636f6 100644 (file)
@@ -25,9 +25,9 @@ import com.badlogic.gdx.utils.reflect.ArrayReflection;
 \r
 /** An ordered or unordered map of objects. This implementation uses arrays to store the keys and values, which means\r
  * {@link #getKey(Object, boolean) gets} do a comparison for each key in the map. This is slower than a typical hash map\r
- * implementation, but may be acceptable for small maps and has the benefits that keys and values can be accessed by\r
- * index, which makes iteration fast. Like {@link Array}, if ordered is false, * this class avoids a memory copy when\r
- * removing elements (the last element is moved to the removed element's position).\r
+ * implementation, but may be acceptable for small maps and has the benefits that keys and values can be accessed by index, which\r
+ * makes iteration fast. Like {@link Array}, if ordered is false, * this class avoids a memory copy when removing elements (the\r
+ * last element is moved to the removed element's position).\r
  * @author Nathan Sweet */\r
 public class ArrayMap<K, V> {\r
        public K[] keys;\r
@@ -334,6 +334,7 @@ public class ArrayMap<K, V> {
        /** Reduces the size of the backing arrays to the size of the actual number of entries. This is useful to release memory when\r
         * many items have been removed, or if it is known that more entries will not be added. */\r
        public void shrink () {\r
+               if (keys.length == size) return;\r
                resize(size);\r
        }\r
 \r
index c7eb617..7d30188 100644 (file)
@@ -69,7 +69,7 @@ public class BooleanArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public BooleanArray (boolean ordered, boolean[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -188,6 +188,7 @@ public class BooleanArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index 0a7249d..bb8c2d3 100644 (file)
@@ -67,7 +67,7 @@ public class CharArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public CharArray (boolean ordered, char[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -219,6 +219,7 @@ public class CharArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index 3d7b4e6..413e9c4 100644 (file)
@@ -67,7 +67,7 @@ public class FloatArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public FloatArray (boolean ordered, float[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -88,7 +88,7 @@ public class FloatArray {
                addAll(array.items, offset, length);\r
        }\r
 \r
-       public void addAll (float[] array) {\r
+       public void addAll (float... array) {\r
                addAll(array, 0, array.length);\r
        }\r
 \r
@@ -219,6 +219,7 @@ public class FloatArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index 0f1f142..62c963d 100644 (file)
@@ -67,7 +67,7 @@ public class IntArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public IntArray (boolean ordered, int[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -219,6 +219,7 @@ public class IntArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index a420231..e9c3a20 100644 (file)
@@ -67,7 +67,7 @@ public class LongArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public LongArray (boolean ordered, long[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -219,6 +219,7 @@ public class LongArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r
index cf1eae5..bf1a490 100644 (file)
@@ -67,7 +67,7 @@ public class ShortArray {
         * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
         *           memory copy. */\r
        public ShortArray (boolean ordered, short[] array, int startIndex, int count) {\r
-               this(ordered, array.length);\r
+               this(ordered, count);\r
                size = count;\r
                System.arraycopy(array, startIndex, items, 0, count);\r
        }\r
@@ -226,6 +226,7 @@ public class ShortArray {
        /** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
         * been removed, or if it is known that more items will not be added. */\r
        public void shrink () {\r
+               if (items.length == size) return;\r
                resize(size);\r
        }\r
 \r