incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1555024 - in /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource: JcrPropertyMap.java internal/JcrModifiableValueMap.java
Date Fri, 03 Jan 2014 07:36:11 GMT
Author: cziegeler
Date: Fri Jan  3 07:36:11 2014
New Revision: 1555024

URL: http://svn.apache.org/r1555024
Log:
SLING-3304 : Optimize JcrPropertyMap.escapeKeyName(). Apply patch from  Przemo Pakulski and
add the same code to JcrModifiableValueMap

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1555024&r1=1555023&r2=1555024&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Fri Jan  3 07:36:11 2014
@@ -68,9 +68,12 @@ public class JcrPropertyMap
     /** A cache for the values. */
     final Map<String, Object> valueCache;
 
-    /** Has the node been read completly? */
+    /** Has the node been read completely? */
     boolean fullyRead;
 
+    /** keep all prefixes for escaping */
+    private String[] namespacePrefixes;
+
     private final ClassLoader dynamicClassLoader;
 
     /**
@@ -380,8 +383,7 @@ public class JcrPropertyMap
         // check if colon is neither the first nor the last character
         if (indexOfPrefix > 0 && key.length() > indexOfPrefix + 1) {
             final String prefix = key.substring(0, indexOfPrefix);
-            for (final String existingPrefix : getNode().getSession()
-                    .getNamespacePrefixes()) {
+            for (final String existingPrefix : getNamespacePrefixes()) {
                 if (existingPrefix.equals(prefix)) {
                     return prefix
                             + ":"
@@ -394,6 +396,16 @@ public class JcrPropertyMap
     }
 
     /**
+    * Read namespace prefixes and store as member variable to minimize number of JCR API
calls
+    */
+    private String[] getNamespacePrefixes() throws RepositoryException {
+        if (this.namespacePrefixes == null) {
+            this.namespacePrefixes = getNode().getSession().getNamespacePrefixes();
+        }
+        return this.namespacePrefixes;
+    }
+
+    /**
      * Read all properties.
      * @throws IllegalArgumentException if a repository exception occurs
      */

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java?rev=1555024&r1=1555023&r2=1555024&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
Fri Jan  3 07:36:11 2014
@@ -73,6 +73,9 @@ public final class JcrModifiableValueMap
     /** Has the node been read completely? */
     private boolean fullyRead;
 
+    /** keep all prefixes for escaping */
+    private String[] namespacePrefixes;
+
     private final ClassLoader dynamicClassLoader;
 
     /**
@@ -371,8 +374,7 @@ public final class JcrModifiableValueMap
         // check if colon is neither the first nor the last character
         if (indexOfPrefix > 0 && key.length() > indexOfPrefix + 1) {
             final String prefix = key.substring(0, indexOfPrefix);
-            for (final String existingPrefix : getNode().getSession()
-                    .getNamespacePrefixes()) {
+            for (final String existingPrefix : getNamespacePrefixes()) {
                 if (existingPrefix.equals(prefix)) {
                     return prefix
                             + ":"
@@ -385,6 +387,16 @@ public final class JcrModifiableValueMap
     }
 
     /**
+    * Read namespace prefixes and store as member variable to minimize number of JCR API
calls
+    */
+    private String[] getNamespacePrefixes() throws RepositoryException {
+        if (this.namespacePrefixes == null) {
+            this.namespacePrefixes = getNode().getSession().getNamespacePrefixes();
+        }
+        return this.namespacePrefixes;
+    }
+
+    /**
      * Read all properties.
      * @throws IllegalArgumentException if a repository exception occurs
      */



Mime
View raw message