ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r806471 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
Date Fri, 21 Aug 2009 09:15:49 GMT
Author: bodewig
Date: Fri Aug 21 09:15:45 2009
New Revision: 806471

URL: http://svn.apache.org/viewvc?rev=806471&view=rev
Log:
cache iterator in Resources if asked for size

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java?rev=806471&r1=806470&r2=806471&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java Fri Aug 21
09:15:45 2009
@@ -32,6 +32,7 @@
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.DataType;
 import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.util.CollectionUtils;
 
 /**
  * Generic ResourceCollection: Either stores nested ResourceCollections,
@@ -66,19 +67,21 @@
     };
 
     private class MyCollection extends AbstractCollection {
-        private int size;
+        private Collection cache;
 
         MyCollection() {
-            size = 0;
-            for (Iterator rci = getNested().iterator(); rci.hasNext();) {
-                size += ((ResourceCollection) rci.next()).size();
-            }
         }
         public int size() {
-            return size;
+            return getCache().size();
         }
-        public Iterator iterator() {
-            return new MyIterator();
+        public synchronized Iterator iterator() {
+            return cache != null ? cache.iterator() : new MyIterator();
+        }
+        private synchronized Collection getCache() {
+            if (cache == null) {
+                cache = CollectionUtils.asCollection(new MyIterator());
+            }
+            return cache;
         }
         private class MyIterator implements Iterator {
             private Iterator rci = getNested().iterator();



Mime
View raw message