| 29 | /// avoids that overhead, which matters when a single tile holds tens of |
| 30 | /// thousands of coordinates. |
| 31 | final class IntArray { |
| 32 | |
| 33 | private int[] data; |
| 34 | private int size; |
| 35 | |
| 36 | IntArray() { |
| 37 | this(16); |
| 38 | } |
| 39 | |
| 40 | IntArray(int initialCapacity) { |
| 41 | data = new int[initialCapacity < 4 ? 4 : initialCapacity]; |
| 42 | } |
| 43 | |
| 44 | void add(int value) { |
| 45 | if (size == data.length) { |
| 46 | int[] grown = new int[data.length * 2]; |
| 47 | System.arraycopy(data, 0, grown, 0, size); |
| 48 | data = grown; |
| 49 | } |
| 50 | data[size++] = value; |
| 51 | } |
| 52 | |
| 53 | int get(int index) { |
| 54 | return data[index]; |
| 55 | } |
| 56 | |
| 57 | int size() { |
| 58 | return size; |
| 59 | } |
| 60 | |
| 61 | void clear() { |
| 62 | size = 0; |
| 63 | } |
| 64 | |
| 65 | /// A trimmed copy holding exactly [#size] elements. |
| 66 | int[] toArray() { |
| 67 | int[] out = new int[size]; |
| 68 | System.arraycopy(data, 0, out, 0, size); |
| 69 | return out; |
| 70 | } |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected