jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1387472 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Date Wed, 19 Sep 2012 07:41:37 GMT
Author: mreutegg
Date: Wed Sep 19 07:41:37 2012
New Revision: 1387472

URL: http://svn.apache.org/viewvc?rev=1387472&view=rev
Log:
OAK-201: NamespaceRegistry is very slow

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1387472&r1=1387471&r2=1387472&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Sep 19 07:41:37 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import java.security.AccessControlException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
@@ -433,11 +434,11 @@ public class SessionImpl extends Abstrac
 
     //--------------------------------------------------< Namespaces >---
 
-    // The code below is copied from JCR Commons AbstractSession, but provides information
-    // the "hasRemappings" information
+    // The code below was initially copied from JCR Commons AbstractSession, but
+    // provides information the "hasRemappings" information
 
     /**
-     * Local namespace mappings. Prefixes as keys and namespace URIs as values.
+     * Local namespace remappings. Prefixes as keys and namespace URIs as values.
      * <p>
      * This map is only accessed from synchronized methods (see
      * <a href="https://issues.apache.org/jira/browse/JCR-1793">JCR-1793</a>).
@@ -485,13 +486,17 @@ public class SessionImpl extends Abstrac
 
     @Override
     public String[] getNamespacePrefixes() throws RepositoryException {
-        for (String uri : getWorkspace().getNamespaceRegistry().getURIs()) {
-            getNamespacePrefix(uri);
-        }
-
+        Set<String> uris = new HashSet<String>();
+        uris.addAll(Arrays.asList(getWorkspace().getNamespaceRegistry().getURIs()));
         synchronized (namespaces) {
-            return namespaces.keySet().toArray(new String[namespaces.size()]);
+            // Add namespace uris only visible to session
+            uris.addAll(namespaces.values());
         }
+        Set<String> prefixes = new HashSet<String>();
+        for (String uri : uris) {
+            prefixes.add(getNamespacePrefix(uri));
+        }
+        return prefixes.toArray(new String[prefixes.size()]);
     }
 
     @Override
@@ -507,9 +512,6 @@ public class SessionImpl extends Abstrac
                     // so there are no mappings for this prefix
                     throw new NamespaceException("Namespace not found: " + prefix);
                 }
-                // Add the mapping to the local set, we already know that
-                // the prefix is not taken
-                namespaces.put(prefix, uri);
             }
 
             return uri;
@@ -534,7 +536,9 @@ public class SessionImpl extends Abstrac
                 prefix = base + i;
             }
 
-            namespaces.put(prefix, uri);
+            if (!base.equals(prefix)) {
+                namespaces.put(prefix, uri);
+            }
             return prefix;
         }
     }



Mime
View raw message