inference: copy variables optimization

This commit is contained in:
Anna Kozlova
2016-01-19 20:46:08 +01:00
parent 2e5a653777
commit 5a0c674952
3 changed files with 18 additions and 19 deletions
@@ -240,17 +240,17 @@ public class InferenceIncorporationPhase {
final InferenceVariable inferenceVar = mySession.getInferenceVariable(eqBound);
if (inferenceVar != null) {
for (InferenceBound inferenceBound : InferenceBound.values()) {
final Set<PsiType> oldVarBounds = inferenceVar.getReadOnlyBoundsSet(inferenceBound);
final Set<PsiType> oldVariableBounds = inferenceVariable.getReadOnlyBoundsSet(inferenceBound);
final List<PsiType> oldVarBounds = inferenceVar.getReadOnlyBounds(inferenceBound);
final List<PsiType> 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);
}
}
@@ -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<InferenceVariable> varsToResolve,
Set<ConstraintFormula> additionalConstraints) {
//resolve input variables
PsiSubstitutor substitutor = resolveSubsetOrdered(varsToResolve, siteSubstitutor);
Set<ConstraintFormula> additionalConstraints,
PsiSubstitutor substitutor) {
if (myContext instanceof PsiCall) {
PsiExpressionList argumentList = ((PsiCall)myContext).getArgumentList();
@@ -35,7 +35,7 @@ public class InferenceVariable extends LightTypeParameter {
}
private boolean myThrownBound = false;
private final Map<InferenceBound, Set<PsiType>> myBounds = new HashMap<InferenceBound, Set<PsiType>>();
private final Map<InferenceBound, List<PsiType>> myBounds = new HashMap<InferenceBound, List<PsiType>>();
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<PsiType> bounds = myBounds.get(inferenceBound);
List<PsiType> bounds = myBounds.get(inferenceBound);
if (bounds == null) {
bounds = new LinkedHashSet<PsiType>();
bounds = new ArrayList<PsiType>();
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<PsiType> getBounds(InferenceBound inferenceBound) {
final Set<PsiType> bounds = myBounds.get(inferenceBound);
final List<PsiType> bounds = myBounds.get(inferenceBound);
return bounds != null ? new ArrayList<PsiType>(bounds) : Collections.<PsiType>emptyList();
}
public Set<PsiType> getReadOnlyBoundsSet(InferenceBound inferenceBound) {
final Set<PsiType> bounds = myBounds.get(inferenceBound);
return bounds != null ? bounds : Collections.<PsiType>emptySet();
public List<PsiType> getReadOnlyBounds(InferenceBound inferenceBound) {
final List<PsiType> bounds = myBounds.get(inferenceBound);
return bounds != null ? bounds : Collections.<PsiType>emptyList();
}
public Set<InferenceVariable> getDependencies(InferenceSession session) {
final Set<InferenceVariable> dependencies = new LinkedHashSet<InferenceVariable>();
for (Set<PsiType> boundTypes : myBounds.values()) {
for (Collection<PsiType> boundTypes : myBounds.values()) {
if (boundTypes != null) {
for (PsiType bound : boundTypes) {
session.collectDependencies(bound, dependencies);