You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2022/09/20 14:34:21 UTC

[jena] branch main updated: GH-1548: GraphBase.isEmpty() no longer iterates all data.

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

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 21e4508a98 GH-1548: GraphBase.isEmpty() no longer iterates all data.
     new 23cff68f5e Merge pull request #1549 from Aklakan/GH-1548
21e4508a98 is described below

commit 21e4508a98aade5e12a9c0bfe13bd5fd1fdb9d99
Author: Claus Stadler <Ra...@googlemail.com>
AuthorDate: Tue Sep 20 16:22:01 2022 +0200

    GH-1548: GraphBase.isEmpty() no longer iterates all data.
---
 .../src/main/java/org/apache/jena/graph/impl/GraphBase.java   | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/jena-core/src/main/java/org/apache/jena/graph/impl/GraphBase.java b/jena-core/src/main/java/org/apache/jena/graph/impl/GraphBase.java
index 8da2c70382..239c0d1633 100644
--- a/jena-core/src/main/java/org/apache/jena/graph/impl/GraphBase.java
+++ b/jena-core/src/main/java/org/apache/jena/graph/impl/GraphBase.java
@@ -317,14 +317,19 @@ public abstract class GraphBase implements GraphWithPerform
 
     /**
      	Answer true iff this graph contains no triples (hidden reification quads do
-        not count). The default implementation is <code>size() == 0</code>, which is
-        fine if <code>size</code> is reasonable efficient. Subclasses may override
+        not count). The default implementation tests whether the iterator returned by
+        {@link #find()} can yield at least one item. Subclasses may override
         if necessary. This method may become final and defined in terms of other
         methods.
     */
     @Override
     public boolean isEmpty()
-        { return size() == 0; }
+        {
+            checkOpen() ;
+            ExtendedIterator<Triple> it = GraphUtil.findAll( this );
+            try { return !it.hasNext(); }
+            finally { it.close(); }
+        }
 
     /**
          Answer true iff this graph is isomorphic to <code>g</code> according to