do not create empty array in clone

This commit is contained in:
2017-09-29 17:46:00 +02:00
parent 235565bfe4
commit 5112fcdfa0

View File

@@ -402,7 +402,7 @@ public class IntList implements Serializable, Cloneable {
public IntList clone() { public IntList clone() {
try { try {
final IntList result = (IntList) super.clone(); final IntList result = (IntList) super.clone();
result.data = Arrays.copyOf(data, index); result.data = index == 0 ? EMPTY_ARRAY : Arrays.copyOf(data, index);
return result; return result;
} catch (final CloneNotSupportedException e) { } catch (final CloneNotSupportedException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);