From 5a0c674952f5ceebf8f7e18e09fe357bebcc6979 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 19 Jan 2016 17:17:05 +0100 Subject: [PATCH] inference: copy variables optimization --- .../InferenceIncorporationPhase.java | 8 ++++---- .../graphInference/InferenceSession.java | 10 ++++------ .../graphInference/InferenceVariable.java | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index 58cbc78e861a..47ac9d83b16e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -240,17 +240,17 @@ public class InferenceIncorporationPhase { final InferenceVariable inferenceVar = mySession.getInferenceVariable(eqBound); if (inferenceVar != null) { for (InferenceBound inferenceBound : InferenceBound.values()) { - final Set oldVarBounds = inferenceVar.getReadOnlyBoundsSet(inferenceBound); - final Set oldVariableBounds = inferenceVariable.getReadOnlyBoundsSet(inferenceBound); + final List oldVarBounds = inferenceVar.getReadOnlyBounds(inferenceBound); + final List oldVariableBounds = inferenceVariable.getReadOnlyBounds(inferenceBound); for (PsiType bound : oldVariableBounds) { - if (!oldVarBounds.contains(bound) && mySession.getInferenceVariable(bound) != inferenceVar) { + if (mySession.getInferenceVariable(bound) != inferenceVar) { needFurtherIncorporation |= inferenceVar.addBound(bound, inferenceBound, this); } } for (PsiType bound : oldVarBounds) { - if (!oldVariableBounds.contains(bound) && mySession.getInferenceVariable(bound) != inferenceVariable) { + if (mySession.getInferenceVariable(bound) != inferenceVariable) { needFurtherIncorporation |= inferenceVariable.addBound(bound, inferenceBound, this); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 4ced9fde48ed..5a58e0066787 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -1267,8 +1267,9 @@ public class InferenceSession { } } + final PsiSubstitutor substitutor = resolveSubsetOrdered(varsToResolve, siteSubstitutor); for (ConstraintFormula formula : subset) { - if (!processOneConstraint(formula, siteSubstitutor, varsToResolve, additionalConstraints)) return false; + if (!processOneConstraint(formula, additionalConstraints, substitutor)) return false; } } return true; @@ -1285,11 +1286,8 @@ public class InferenceSession { } private boolean processOneConstraint(ConstraintFormula formula, - PsiSubstitutor siteSubstitutor, - Set varsToResolve, - Set additionalConstraints) { - //resolve input variables - PsiSubstitutor substitutor = resolveSubsetOrdered(varsToResolve, siteSubstitutor); + Set additionalConstraints, + PsiSubstitutor substitutor) { if (myContext instanceof PsiCall) { PsiExpressionList argumentList = ((PsiCall)myContext).getArgumentList(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java index f8d78999db07..84279bf978ba 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java @@ -35,7 +35,7 @@ public class InferenceVariable extends LightTypeParameter { } private boolean myThrownBound = false; - private final Map> myBounds = new HashMap>(); + private final Map> myBounds = new HashMap>(); private final String myName; private PsiType myInstantiation = PsiType.NULL; @@ -71,9 +71,9 @@ public class InferenceVariable extends LightTypeParameter { PsiUtil.resolveClassInClassTypeOnly(classType) == this) { return false; } - Set bounds = myBounds.get(inferenceBound); + List bounds = myBounds.get(inferenceBound); if (bounds == null) { - bounds = new LinkedHashSet(); + bounds = new ArrayList(); myBounds.put(inferenceBound, bounds); } @@ -81,7 +81,8 @@ public class InferenceVariable extends LightTypeParameter { classType = PsiType.NULL; } - if (bounds.add(classType)) { + if (incorporationPhase == null || !bounds.contains(classType)) { + bounds.add(classType); if (incorporationPhase != null) { incorporationPhase.addBound(this, classType, inferenceBound); } @@ -91,18 +92,18 @@ public class InferenceVariable extends LightTypeParameter { } public List getBounds(InferenceBound inferenceBound) { - final Set bounds = myBounds.get(inferenceBound); + final List bounds = myBounds.get(inferenceBound); return bounds != null ? new ArrayList(bounds) : Collections.emptyList(); } - public Set getReadOnlyBoundsSet(InferenceBound inferenceBound) { - final Set bounds = myBounds.get(inferenceBound); - return bounds != null ? bounds : Collections.emptySet(); + public List getReadOnlyBounds(InferenceBound inferenceBound) { + final List bounds = myBounds.get(inferenceBound); + return bounds != null ? bounds : Collections.emptyList(); } public Set getDependencies(InferenceSession session) { final Set dependencies = new LinkedHashSet(); - for (Set boundTypes : myBounds.values()) { + for (Collection boundTypes : myBounds.values()) { if (boundTypes != null) { for (PsiType bound : boundTypes) { session.collectDependencies(bound, dependencies);