You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/10/09 09:02:30 UTC

[sling-org-apache-sling-jcr-resource] 01/01: SLING-11614 avoid duplicate creation of child node iterator

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

joerghoh pushed a commit to branch SLING-11614-optimize-listJcrChildren
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git

commit bb3d2e9dcab41da64bfad950db87d01838c1f4cf
Author: Jörg Hoh <jo...@joerghoh.de>
AuthorDate: Sun Oct 9 11:02:09 2022 +0200

    SLING-11614 avoid duplicate creation of child node iterator
---
 .../sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
index dba7f67..9371aa5 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import javax.jcr.Item;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 
@@ -217,15 +218,13 @@ class JcrNodeResource extends JcrItemResource<Node> { // this should be package
         return null;
     }
 
-
-    // ---------- Descendable interface ----------------------------------------
-
     @Override
     @Nullable Iterator<Resource> listJcrChildren() {
         try {
-            if (getNode().hasNodes()) {
+        	NodeIterator iter = getNode().getNodes();
+            if (iter.hasNext()) {
                 return new JcrNodeResourceIterator(getResourceResolver(), path, version,
-                        getNode().getNodes(), this.helper, null);
+                        iter, this.helper, null);
             }
         } catch (final RepositoryException re) {
             LOGGER.error("listChildren: Cannot get children of " + this, re);