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)`.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---