From 0fa80ee295edc0d089a663c5bd0a91cf1203dc60 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 2 Dec 2000 04:13:52 +0000 Subject: Vector.java (insertElementAt): Unconditionally increment elementCount. * java/util/Vector.java (insertElementAt): Unconditionally increment elementCount. (removeRange): Clear unused slots in vector. From-SVN: r37944 --- libjava/java/util/Vector.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'libjava/java/util/Vector.java') diff --git a/libjava/java/util/Vector.java b/libjava/java/util/Vector.java index 06d2ebe..1678590 100644 --- a/libjava/java/util/Vector.java +++ b/libjava/java/util/Vector.java @@ -440,8 +440,9 @@ public class Vector extends AbstractList throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); if (elementCount == elementData.length) - ensureCapacity(++elementCount); - modCount++; + ensureCapacity(elementCount + 1); + ++modCount; + ++elementCount; System.arraycopy(elementData, index, elementData, index + 1, elementCount - 1 - index); elementData[index] = obj; @@ -755,7 +756,11 @@ public class Vector extends AbstractList { System.arraycopy(elementData, toIndex, elementData, fromIndex, elementCount - toIndex); + // Clear unused elements so objects can be collected. + int save = elementCount; elementCount -= (toIndex - fromIndex); + for (int i = elementCount; i < save; ++i) + elementData[i] = null; } } } -- cgit v1.1