Mercurial > jhg
diff src/org/tmatesoft/hg/internal/IntVector.java @ 551:4ea0351ca878
Better (precise) name for diff facility, tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 20 Feb 2013 18:19:52 +0100 |
parents | 83afa680555d |
children | 45751456b471 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/IntVector.java Tue Feb 19 21:35:09 2013 +0100 +++ b/src/org/tmatesoft/hg/internal/IntVector.java Wed Feb 20 18:19:52 2013 +0100 @@ -42,11 +42,20 @@ public void add(int v) { if (count == data.length) { - grow(); + grow(0); } data[count++] = v; } + public void add(int... values) { + if (count + values.length > data.length) { + grow(count + values.length - data.length); + } + for (int v : values) { + data[count++] = v; + } + } + public int get(int i) { if (i < 0 || i >= count) { throw new IndexOutOfBoundsException(String.format("Index: %d, size: %d", i, count)); @@ -95,11 +104,14 @@ return toArray(); } - private void grow() { + private void grow(int newCapacityHint) { if (increment == 0) { throw new UnsupportedOperationException("This vector is not allowed to expand"); } int newCapacity = increment < 0 ? data.length << 1 : data.length + increment; + if (newCapacityHint > 0 && newCapacity < newCapacityHint) { + newCapacity = newCapacityHint; + } assert newCapacity > 0 && newCapacity != data.length : newCapacity; int[] newData = new int[newCapacity]; System.arraycopy(data, 0, newData, 0, count);