Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2017-06-06 09:54:03 +0000
committerLaurent Goubet2017-06-06 13:18:01 +0000
commit8ed4ef9f3032aee0aead5245f36d22126b56bc77 (patch)
tree7060272793015aaeef1214ca0f7777e9eeba36aa
parentce535306d74529bddffcc05894c98abff8c594a4 (diff)
downloadorg.eclipse.emf.compare-8ed4ef9f3032aee0aead5245f36d22126b56bc77.tar.gz
org.eclipse.emf.compare-8ed4ef9f3032aee0aead5245f36d22126b56bc77.tar.xz
org.eclipse.emf.compare-8ed4ef9f3032aee0aead5245f36d22126b56bc77.zip
Revert "Refactorings to improve performance of MatchUtil"3.3.1RC3
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java130
1 files changed, 49 insertions, 81 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
index 4dc4dae4a..d8a526b16 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2017 Obeo and others.
+ * Copyright (c) 2012, 2016 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,7 +8,6 @@
* Contributors:
* Obeo - initial API and implementation
* Michael Borkowski - bug 467576
- * Philip Langer - performance improvements
*******************************************************************************/
package org.eclipse.emf.compare.utils;
@@ -21,11 +20,10 @@ import static org.eclipse.emf.compare.utils.EMFComparePredicates.CONTAINMENT_REF
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueIs;
-import static org.eclipse.emf.compare.utils.ReferenceUtil.safeEGet;
+import static org.eclipse.emf.compare.utils.ReferenceUtil.getAsList;
import com.google.common.collect.Iterables;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.URI;
@@ -36,12 +34,11 @@ import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.util.CompareSwitch;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.util.InternalEList;
/**
* This utility class holds methods that will be used by the diff and merge processes.
@@ -289,18 +286,16 @@ public final class MatchUtil {
throw new IllegalArgumentException();
}
if (source == DifferenceSource.LEFT) {
- final EObject left = match.getLeft();
- if (featureContains(left, feature, value)) {
- result = left;
+ if (featureContains(match.getLeft(), feature, value)) {
+ result = match.getLeft();
} else if (comparison.isThreeWay()) {
result = match.getOrigin();
} else {
result = match.getRight();
}
} else {
- final EObject right = match.getRight();
- if (featureContains(right, feature, value)) {
- result = right;
+ if (featureContains(match.getRight(), feature, value)) {
+ result = match.getRight();
} else if (comparison.isThreeWay()) {
result = match.getOrigin();
} else {
@@ -331,50 +326,27 @@ public final class MatchUtil {
// public for testing
public static boolean featureContains(EObject eObject, EStructuralFeature feature, Object value) {
boolean contains = false;
-
- if (eObject != null && feature != null) {
- final Object featureValue = safeEGet(eObject, feature);
- if (feature.isMany()) {
- // only compute the value's URI once, and only if needed
- URI valueURI = null;
- final Iterator<?> i;
- if (featureValue instanceof InternalEList<?>) {
- i = ((InternalEList<?>)featureValue).basicIterator();
- } else {
- i = ((List<?>)featureValue).iterator();
- }
- while (i.hasNext()) {
- final Object element = i.next();
- if (element == value) {
- contains = true;
- break;
- }
- if (element != null && element.equals(value)) {
- contains = true;
- break;
- }
- URI proxyURI = getProxyURI(element);
- if (proxyURI != null) {
- if (valueURI == null && value instanceof EObject) {
- valueURI = EcoreUtil.getURI((EObject)value);
- }
- if (proxyURI.equals(valueURI)) {
- contains = true;
- break;
- }
- }
- }
- } else if (featureValue == value) {
+ // only compute the value's URI once, and only if needed
+ URI valueURI = null;
+
+ for (Object element : getAsList(eObject, feature)) {
+ if (element == value) {
contains = true;
- } else if (featureValue != null && featureValue.equals(value)) {
+ break;
+ }
+ if (element != null && element.equals(value)) {
contains = true;
- } else {
- URI proxyURI = getProxyURI(featureValue);
- if (proxyURI != null && value instanceof EObject) {
- if (proxyURI.equals(EcoreUtil.getURI((EObject)value))) {
- contains = true;
- }
+ break;
+ }
+
+ if (element instanceof EObject && ((EObject)element).eIsProxy()) {
+ if (valueURI == null && value instanceof EObject) {
+ valueURI = EcoreUtil.getURI((EObject)value);
+ }
+ if (EcoreUtil.getURI((EObject)element).equals(valueURI)) {
+ contains = true;
+ break;
}
}
}
@@ -383,20 +355,6 @@ public final class MatchUtil {
}
/**
- * Returns the proxy URI of the object if it's an EObject.
- *
- * @param object
- * the object to test.
- * @return the proxy URI.
- */
- private static URI getProxyURI(Object object) {
- if (object instanceof InternalEObject) {
- return ((InternalEObject)object).eProxyURI();
- }
- return null;
- }
-
- /**
* Get the value of any difference.
*
* @param input
@@ -404,14 +362,19 @@ public final class MatchUtil {
* @return the value of the difference.
*/
public static Object getValue(Diff input) {
- if (input instanceof AttributeChange) {
- return ((AttributeChange)input).getValue();
- }
- if (input instanceof ReferenceChange) {
- return ((ReferenceChange)input).getValue();
- }
+ final CompareSwitch<Object> customSwitch = new CompareSwitch<Object>() {
+ @Override
+ public Object caseAttributeChange(AttributeChange object) {
+ return object.getValue();
+ }
- return null;
+ @Override
+ public Object caseReferenceChange(ReferenceChange object) {
+ return object.getValue();
+ }
+
+ };
+ return customSwitch.doSwitch(input);
}
/**
@@ -422,14 +385,19 @@ public final class MatchUtil {
* @return the structural feature.
*/
public static EStructuralFeature getStructuralFeature(Diff input) {
- if (input instanceof AttributeChange) {
- return ((AttributeChange)input).getAttribute();
- }
- if (input instanceof ReferenceChange) {
- return ((ReferenceChange)input).getReference();
- }
+ final CompareSwitch<EStructuralFeature> customSwitch = new CompareSwitch<EStructuralFeature>() {
+ @Override
+ public EStructuralFeature caseAttributeChange(AttributeChange object) {
+ return object.getAttribute();
+ }
- return null;
+ @Override
+ public EStructuralFeature caseReferenceChange(ReferenceChange object) {
+ return object.getReference();
+ }
+
+ };
+ return customSwitch.doSwitch(input);
}
/**

Back to the top