You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2022/09/21 12:08:50 UTC

[GitHub] [jena] afs commented on a diff in pull request #1550: GH-1548: Succinct isEmpty() test. Aligned with DatasetGraphBase.

afs commented on code in PR #1550:
URL: https://github.com/apache/jena/pull/1550#discussion_r976423906


##########
jena-core/src/main/java/org/apache/jena/graph/impl/GraphBase.java:
##########
@@ -317,18 +317,15 @@ protected int graphBaseSize()
 
     /**
      	Answer true iff this graph contains no triples (hidden reification quads do
-        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
+        not count). The default implementation tests whether {@link #contains(Node, Node, Node)}
+        with only {@link Node#ANY} arguments returns false.
+        Subclasses may override if necessary. This method may become final and defined in terms of other
         methods.
     */
     @Override
     public boolean isEmpty()
         {
-            checkOpen() ;
-            ExtendedIterator<Triple> it = GraphUtil.findAll( this );
-            try { return !it.hasNext(); }
-            finally { it.close(); }
+            return !contains( Node.ANY, Node.ANY, Node.ANY );

Review Comment:
   `return !contains( Triple.ANY);` avoids the object creation in the default impl path of `contains`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org