Improve addAll for empty-other case
spelling fix
@@ -22,7 +22,7 @@ public ASN1EncodableVector(int initialCapacity)
{
if (initialCapacity < 0)
{
- throw new IllegalArgumentException("'initialCapacity' must not ne negative");
+ throw new IllegalArgumentException("'initialCapacity' must not be negative");
}
this.elements = (initialCapacity == 0) ? EMPTY_ELEMENTS : new ASN1Encodable[initialCapacity];
@@ -56,6 +56,10 @@ public void addAll(ASN1EncodableVector other)
}
int otherElementCount = other.size();
+ if (otherElementCount < 1)
+ {
+ return;
+ }
int capacity = elements.length;
int minCapacity = elementCount + otherElementCount;
@@ -64,7 +68,8 @@ public void addAll(ASN1EncodableVector other)
reallocate(minCapacity);
}
- for (int i = 0; i < otherElementCount; ++i)
+ int i = 0;
+ do
{
ASN1Encodable otherElement = other.get(i);
if (null == otherElement)
@@ -74,6 +79,7 @@ public void addAll(ASN1EncodableVector other)
this.elements[elementCount + i] = otherElement;
}
+ while (++i < otherElementCount);
this.elementCount = minCapacity;
}
