[ 
https://issues.apache.org/jira/browse/JENA-1284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15848476#comment-15848476
 ] 

ASF GitHub Bot commented on JENA-1284:
--------------------------------------

Github user ajs6f commented on a diff in the pull request:

    https://github.com/apache/jena/pull/212#discussion_r98912881
  
    --- Diff: jena-core/src/main/java/org/apache/jena/graph/GraphUtil.java ---
    @@ -115,55 +117,44 @@ public static void add(Graph graph, Triple[] triples) 
{
         }
             
         public static void add(Graph graph, List<Triple> triples) {
    +        addIteratorWorkerDirect(graph, triples.iterator());
             if ( OldStyle && graph instanceof GraphWithPerform )
    -        {
    -            GraphWithPerform g = (GraphWithPerform)graph ;
    -            for (Triple t : triples)
    -                g.performAdd(t) ;
                 graph.getEventManager().notifyAddList(graph, triples) ;
    -        } else
    -        {
    -            for (Triple t : triples)
    -                graph.add(t) ;
    -        }
         }
             
         public static void add(Graph graph, Iterator<Triple> it) {
    -        // Materialize to avoid ConcurrentModificationException.
    -        List<Triple> s = IteratorCollection.iteratorToList(it) ;
    -        if ( OldStyle && graph instanceof GraphWithPerform )
    -        {
    -            GraphWithPerform g = (GraphWithPerform)graph ;
    -            for (Triple t : s)
    -                g.performAdd(t) ;
    +        if ( OldStyle && graph instanceof GraphWithPerform ) {
    +            // Materialize for the notify.
    +            List<Triple> s = IteratorCollection.iteratorToList(it) ;
    +            addIteratorWorkerDirect(graph, s.iterator());
                 graph.getEventManager().notifyAddIterator(graph, s) ;
             } 
    -        else
    -        {
    -            for (Triple t : s)
    -                graph.add(t) ;
    -        }
    +        else 
    +            addIteratorWorker(graph, it);
         }
         
         /** Add triples into the destination (arg 1) from the source (arg 2)*/
         public static void addInto(Graph dstGraph, Graph srcGraph ) {
    +        if ( dstGraph == srcGraph )
    +            return ;
             
dstGraph.getPrefixMapping().setNsPrefixes(srcGraph.getPrefixMapping()) ;
             addIteratorWorker(dstGraph, GraphUtil.findAll( srcGraph ));  
             dstGraph.getEventManager().notifyAddGraph( dstGraph, srcGraph );
         }
         
         private static void addIteratorWorker( Graph graph, Iterator<Triple> 
it ) { 
             List<Triple> s = IteratorCollection.iteratorToList( it );
    -        if ( OldStyle && graph instanceof GraphWithPerform )
    -        {
    -            GraphWithPerform g = (GraphWithPerform)graph ;
    -            for (Triple t : s )
    -                g.performAdd(t) ;
    -        }
    -        else
    -        {
    -            for (Triple t : s )
    -                graph.add(t) ;
    +        addIteratorWorkerDirect(graph, s.iterator());
    +    }
    +    
    +    private static void addIteratorWorkerDirect( Graph graph, 
Iterator<Triple> it ) {
    +        if ( OldStyle && graph instanceof GraphWithPerform ) {
    +            GraphWithPerform g = (GraphWithPerform)graph;
    +            while (it.hasNext())
    --- End diff --
    
    @ajs6f's usual carping: I really think "point-free" reads more clearly here 
and directly below: `it.forEachRemaining(g::performAdd)`. 


> Improve GraphUtil operations by considering relative graph sizes.
> -----------------------------------------------------------------
>
>                 Key: JENA-1284
>                 URL: https://issues.apache.org/jira/browse/JENA-1284
>             Project: Apache Jena
>          Issue Type: Improvement
>            Reporter: Andy Seaborne
>            Assignee: Andy Seaborne
>
> Some of the bulk `GraphUtil` operations, `addInto` and `deleteFrom`, could be 
> improved to loop on the smaller graph and have different algorithms depending 
> on whether source or destination graph is smaller.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to