[jboss-cvs] JBossAS SVN: r114826 - projects/jboss-deployers/branches/deployers-vfs-spi-2.0.10.GA-JBPAPP-11187/src/main/java/org/jboss/deployers/vfs/spi/structure/modified.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 24 18:14:21 EDT 2014


Author: bmaxwell
Date: 2014-09-24 18:14:20 -0400 (Wed, 24 Sep 2014)
New Revision: 114826

Modified:
   projects/jboss-deployers/branches/deployers-vfs-spi-2.0.10.GA-JBPAPP-11187/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
Log:
[JBPAPP-11187] backport  JBPAPP 10721 DefaultStructureCache uses higher CPU than it needs to

Modified: projects/jboss-deployers/branches/deployers-vfs-spi-2.0.10.GA-JBPAPP-11187/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
===================================================================
--- projects/jboss-deployers/branches/deployers-vfs-spi-2.0.10.GA-JBPAPP-11187/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java	2014-09-24 22:12:05 UTC (rev 114825)
+++ projects/jboss-deployers/branches/deployers-vfs-spi-2.0.10.GA-JBPAPP-11187/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java	2014-09-24 22:14:20 UTC (rev 114826)
@@ -26,8 +26,8 @@
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Collections;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Pattern;
+import java.util.concurrent.ConcurrentNavigableMap;
+import java.util.concurrent.ConcurrentSkipListMap;
 
 /**
  * Default structure cache.
@@ -37,7 +37,7 @@
  */
 public class DefaultStructureCache<T> extends AbstractStructureCache<T>
 {
-   private Map<String, T> map = new ConcurrentHashMap<String, T>();
+   private ConcurrentNavigableMap<String, T> map = new ConcurrentSkipListMap<String, T>();
 
    public void initializeCache(String pathName)
    {
@@ -56,11 +56,14 @@
    public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
    {
       Set<String> result = null;
-      Pattern pattern = Pattern.compile(pathName + "/[^/]+");
-      for (String key : map.keySet())
-      {
-         // first the pattern should match, only then we check the filter
-         if (pattern.matcher(key).matches() && (filter == null || filter.accepts(key)))
+      for (Map.Entry<String, T> entry: map.tailMap(pathName).entrySet()) {
+         String key = entry.getKey();
+         if (!key.startsWith(pathName))
+            break;
+
+         boolean matches = (key.length() > pathName.length() &&
+                 key.lastIndexOf('/') == pathName.length());
+         if (matches && (filter == null || filter.accepts(key)))
          {
             if (result == null)
                result = new HashSet<String>();
@@ -81,14 +84,13 @@
 
    public void removeCache(String pathName)
    {
-      Iterator<Map.Entry<String, T>> iter = map.entrySet().iterator();
-      while (iter.hasNext())
-      {
-         Map.Entry<String, T> entry = iter.next();
-         if (entry.getKey().startsWith(pathName))
-         {
-            iter.remove();
-         }
+      Iterator<String> iter = map.tailMap(pathName).keySet().iterator();
+      while (iter.hasNext()) {
+         String key = iter.next();
+         if (!key.startsWith(pathName))
+            break;
+
+         iter.remove();
       }
    }
 
@@ -96,4 +98,4 @@
    {
       map.clear();
    }
-}
\ No newline at end of file
+}



More information about the jboss-cvs-commits mailing list