This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b985f4  SLING-9365: optimize the path lookup
1b985f4 is described below

commit 1b985f41f9266a35fa482a1a66f1c76e8a29c2c2
Author: Karl Pauls <[email protected]>
AuthorDate: Thu Jun 4 00:09:38 2020 +0200

    SLING-9365: optimize the path lookup
---
 .../resolver/internal/ScriptResourceDecorator.java | 31 +++++++++++++---------
 .../resource/MergingServletResourceProvider.java   | 14 ++++++++++
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/servlets/resolver/internal/ScriptResourceDecorator.java
 
b/src/main/java/org/apache/sling/servlets/resolver/internal/ScriptResourceDecorator.java
index 035316f..c8880d1 100644
--- 
a/src/main/java/org/apache/sling/servlets/resolver/internal/ScriptResourceDecorator.java
+++ 
b/src/main/java/org/apache/sling/servlets/resolver/internal/ScriptResourceDecorator.java
@@ -45,22 +45,27 @@ public class ScriptResourceDecorator implements 
ResourceDecorator {
     @Override
     public Resource decorate(Resource resource) {
         String path = ResourceUtil.normalize(resource.getPath());
-        String resolutionPath = 
resource.getResourceMetadata().getResolutionPath();
-        Resource script = getResource(resource, path);
-        if (script == resource && 
Resource.RESOURCE_TYPE_NON_EXISTING.equals(resource.getResourceType())) {
-            int idx = path.indexOf('.');
-            if (idx != -1) {
-                path = path.substring(0, idx);
-                script = getResource(resource, path);
-                resolutionPath = path;
+        if (this.provider.isRootOf(path)) {
+            String resolutionPath = 
resource.getResourceMetadata().getResolutionPath();
+            Resource script = getResource(resource, path);
+            if (script == resource && 
Resource.RESOURCE_TYPE_NON_EXISTING.equals(resource.getResourceType())) {
+                int idx = path.indexOf('.');
+                if (idx != -1) {
+                    path = path.substring(0, idx);
+                    script = getResource(resource, path);
+                    resolutionPath = path;
+                }
             }
+            if (script != resource) {
+                
script.getResourceMetadata().putAll(resource.getResourceMetadata());
+                script.getResourceMetadata().setResolutionPath(resolutionPath);
+            }
+
+            return script;
         }
-        if (script != resource) {
-            
script.getResourceMetadata().putAll(resource.getResourceMetadata());
-            script.getResourceMetadata().setResolutionPath(resolutionPath);
+        else {
+            return resource;
         }
-
-        return script;
     }
 
     @Override
diff --git 
a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/MergingServletResourceProvider.java
 
b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/MergingServletResourceProvider.java
index a73dce0..05ebd46 100644
--- 
a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/MergingServletResourceProvider.java
+++ 
b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/MergingServletResourceProvider.java
@@ -123,6 +123,20 @@ public class MergingServletResourceProvider {
         }
     }
 
+    public boolean isRootOf(String path) {
+        if (path != null && path.startsWith("/")) {
+            int idx = path.indexOf('/', 1);
+            if (idx != -1) {
+                path = path.substring(0, idx);
+                return tree.get().containsKey(path);
+            } else {
+                return true;
+            }
+        } else {
+            return false;
+        }
+    }
+
     public Resource getResource(ResolveContext resolveContext, String path) {
         Resource wrapped = null;
         final ResourceProvider parentProvider = 
resolveContext.getParentResourceProvider();

Reply via email to