add special implementation for add
The special implementation does not need to allocate an array for the varargs of addAll
This commit is contained in:
@@ -112,9 +112,10 @@ public class IntList {
|
||||
* the value to add
|
||||
*/
|
||||
public void add(final int value) {
|
||||
// TODO add a special implementation that does not
|
||||
// need to allocate an array for the varargs of addAll
|
||||
addAll(value);
|
||||
ensureCapacity(1);
|
||||
|
||||
data[index] = value;
|
||||
index++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,11 +39,9 @@ public class IntListTest {
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
final IntList list = new IntList();
|
||||
|
||||
list.addAll();
|
||||
Assert.assertTrue(list.isEmpty());
|
||||
Assert.assertEquals(0, list.size());
|
||||
// setting initial size to one, so that the first add does not need to resize,
|
||||
// but the second add must
|
||||
final IntList list = new IntList(1);
|
||||
|
||||
list.add(1);
|
||||
|
||||
@@ -179,6 +177,10 @@ public class IntListTest {
|
||||
public void testAddArray() {
|
||||
final IntList list = new IntList();
|
||||
|
||||
list.addAll();
|
||||
Assert.assertTrue(list.isEmpty());
|
||||
Assert.assertEquals(0, list.size());
|
||||
|
||||
final int size = 100;
|
||||
final int[] ints = ThreadLocalRandom.current().ints(size).toArray();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user