[jboss-cvs] JBossAS SVN: r87392 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 15 17:23:04 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-04-15 17:23:04 -0400 (Wed, 15 Apr 2009)
New Revision: 87392

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
Log:
Use a hash map and array lists instead of linked lists; results in around 500ms improvement

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-04-15 21:22:22 UTC (rev 87391)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-04-15 21:23:04 UTC (rev 87392)
@@ -41,8 +41,8 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -1029,6 +1029,8 @@
       return false;
    }
 
+   private static final byte[] NO_BYTES = new byte[0];
+
    /**
     * Contents of the file represented by a given handler
     *
@@ -1063,7 +1065,7 @@
       }
 
       if(ei.entry == null)
-         return new ByteArrayInputStream(new byte[0]);
+         return new ByteArrayInputStream(NO_BYTES);
 
       return getZipSource().openStream(ei.entry);
    }
@@ -1171,7 +1173,7 @@
       private ZipEntry entry;
 
       /** a list of children */
-      private List<AbstractVirtualFileHandler> children;
+      private Map<String, AbstractVirtualFileHandler> children;
 
       /**
        * EntryInfo constructor
@@ -1195,7 +1197,7 @@
          if (children == null)
             return Collections.emptyList();
 
-         return new LinkedList<VirtualFileHandler>(children);
+         return new ArrayList<VirtualFileHandler>(children.values());
       }
 
       /**
@@ -1208,15 +1210,9 @@
       {
          if (children != null)
          {
-            int i = 0;
-            for (AbstractVirtualFileHandler child : children)
-            {
-               if (child.getName().equals(original.getName()))
-               {
-                  children.set(i, replacement);
-                  break;
-               }
-               i++;
+            final String name = original.getName();
+            if (children.containsKey(name)) {
+               children.put(name, replacement);
             }
          }
       }
@@ -1239,24 +1235,9 @@
       {
          if (children == null)
          {
-            children = new LinkedList<AbstractVirtualFileHandler>();
+            children = new LinkedHashMap<String, AbstractVirtualFileHandler>();
          }
-         else
-         {
-            // if a child exists with this name already, remove it
-            Iterator<AbstractVirtualFileHandler> it = children.iterator();
-            while (it.hasNext())
-            {
-               AbstractVirtualFileHandler handler = it.next();
-               if (handler.getName().equals(child.getName()))
-               {
-                  it.remove();
-                  break;
-               }
-            }
-         }
-
-         children.add(child);
+         children.put(child.getName(), child);
       }
    }
 




More information about the jboss-cvs-commits mailing list