From 0b7abed55e34bc0a174b64193603c2db15d9d23a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 13 Dec 2010 13:44:48 +0000 Subject: [PATCH] improve performance of VectorSet#add - PR 50200 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1045116 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ src/main/org/apache/tools/ant/util/VectorSet.java | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 50a824a1e..383583dfe 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -286,6 +286,10 @@ Other changes: compile to .class files). Bugzilla Report 48829. + * The performance of VectorSet#add(Object) has been improved which + should also benefit any operation that scans directories in Ant. + Bugzilla Report 50200. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== diff --git a/src/main/org/apache/tools/ant/util/VectorSet.java b/src/main/org/apache/tools/ant/util/VectorSet.java index 235027263..78c0f75d1 100644 --- a/src/main/org/apache/tools/ant/util/VectorSet.java +++ b/src/main/org/apache/tools/ant/util/VectorSet.java @@ -76,13 +76,13 @@ public final class VectorSet extends Vector { // Vector.add seems to delegate to insertElementAt, but this // is not documented so we may better implement it ourselves if (set.add(o)) { - ensureCapacity(size() + 1); - Object[] elems = new Object[elementData.length]; - System.arraycopy(elementData, 0, elems, 0, index); - elems[index] = o; - System.arraycopy(elementData, index, elems, index + 1, - size() - index); - elementData = elems; + int count = size(); + ensureCapacity(count + 1); + if (index != count) { + System.arraycopy(elementData, index, elementData, index + 1, + count - index); + } + elementData[index] = o; elementCount++; } }