I recently wanted to write a function that used ByteBigArrayBigList if ByteArrayList became too small. I passed what I had so far to a constructor for ByteBigArrayBigList. I discovered that Java used the constructor that accepts a ByteCollection. That's fine, except it uses an iterator. I expected it to use something more efficient like getElements, or for there to be a constructor that accepts a ByteList and does something efficient with the array if it's a ByteArrayList.
Would this be a good change, or unnecessary? I expect similar changes would apply to other types.
Current
public ByteBigArrayBigList(final ByteCollection c) {
this(Size64.sizeOf(c));
if (c instanceof ByteBigList) {
((ByteBigList)c).getElements(0, a, 0, size = Size64.sizeOf(c));
} else {
for (ByteIterator i = c.iterator(); i.hasNext();) add(i.nextByte());
}
}
expected
public ByteBigArrayBigList(final ByteCollection c) {
this(Size64.sizeOf(c));
if (c instanceof ByteBigList) {
((ByteBigList) c).getElements(0, a, 0, size = Size64.sizeOf(c));
} else if (c instanceof ByteArrayList) { BigArrays.copy(new byte[][] {((ByteArrayList) c).a}, 0, this.a, 0, size = Size64.sizeOf(c));
} else {
for (ByteIterator i = c.iterator(); i.hasNext();) add(i.nextByte());
}
}
and maybe add
public ByteBigArrayBigList(final ByteList l) {
this(Size64.sizeOf(l));
if (l instanceof ByteArrayList) {
BigArrays.copy(new byte[][] {((ByteArrayList) l).a}, 0, this.a, 0, size = Size64.sizeOf(l));
} else {
for(ByteIterator i = l.iterator(); i.hasNext();) add(i.nextByte());
}
}