Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2019-02-14 04:17:08 -0500
committerlgoubet2019-02-26 04:30:39 -0500
commit0edc017f5f960cc7da60807c24df270d933cd946 (patch)
treef9dfe457d8b500e415fde87c6a15575ece591044
parent43c3ee96775f4effdf91991ffdc1a86803790960 (diff)
downloadorg.eclipse.emf.compare-0edc017f5f960cc7da60807c24df270d933cd946.tar.gz
org.eclipse.emf.compare-0edc017f5f960cc7da60807c24df270d933cd946.tar.xz
org.eclipse.emf.compare-0edc017f5f960cc7da60807c24df270d933cd946.zip
Suppress guava nested concatenations
Concatenating iterators in a loop is exponentially slow and will cause stack overflow errors very fast on medium-sized inputs. Change-Id: I256385b39ef536a9b489260503a1baec4e85f1e0
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java16
1 files changed, 6 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
index 2cd2ec312..bffbb816a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
@@ -29,7 +29,6 @@ import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -38,9 +37,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
@@ -431,14 +431,10 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
* @return An {@link Iterable} over all collected Differences.
*/
private List<Diff> collectDifferences(Comparison comparison, Iterable<Object> objects) {
- Iterable<Diff> differences = ImmutableList.of();
- for (Object object : objects) {
- if (EObject.class.isInstance(object)) {
- EList<Diff> objectDifferences = comparison.getDifferences(EObject.class.cast(object));
- differences = Iterables.concat(differences, objectDifferences);
- }
- }
- return Lists.newArrayList(differences);
+ List<Diff> differences = StreamSupport.stream(objects.spliterator(), false)
+ .filter(EObject.class::isInstance).map(EObject.class::cast)
+ .flatMap(eobject -> comparison.getDifferences(eobject).stream()).collect(Collectors.toList());
+ return differences;
}
/**

Back to the top