Add IntList as a more efficient representation of List<Integer>
commit578232c90d3bce9b1bc9fdd9e4a87d6c8ecd04cf
authorShawn O. Pearce <spearce@spearce.org>
Fri, 12 Dec 2008 02:46:09 +0000 (11 18:46 -0800)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Sat, 13 Dec 2008 02:13:25 +0000 (13 03:13 +0100)
tree67180abea041439f3afe2c49b3b880137b052488
parent37ce31ce1527611e66254de0879e2f500798ad60
Add IntList as a more efficient representation of List<Integer>

Java's generic container types can only handle reference values,
which means making a List of ints requires boxing each value. A
boxed int typically requires at least 12 bytes more space per
value over an unboxed int, as it has an additional object header
and a cell to hold the object reference.

IntList uses an int[] internally to hold the values, rather than
an Object[] like List<Integer> would use.

We don't conform to the List (or even Collection) APIs as doing
so would require that we box return values, which is even less
efficient than just using ArrayList<Integer>, because we would
be boxing every return value each time it is accessed.  Instead
we use an API that smells the same, so there is some finger feel
to using the class.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit.test/tst/org/spearce/jgit/util/IntListTest.java [new file with mode: 0644]
org.spearce.jgit/src/org/spearce/jgit/util/IntList.java [new file with mode: 0644]