diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 13049c889..014500bc2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -29,6 +29,9 @@ public final class ExtendsType extends WildcardType { */ @Override public UnifyType setTypeParams(TypeParams newTp) { + UnifyType newType = wildcardedType.setTypeParams(newTp); + if(newType == wildcardedType) + return this; // Reduced the amount of objects created return new ExtendsType(wildcardedType.setTypeParams(newTp)); } @@ -45,8 +48,8 @@ public final class ExtendsType extends WildcardType { @Override UnifyType apply(Unifier unif) { UnifyType newType = wildcardedType.apply(unif); - /*if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) - return this; // Reduced the amount of objects created*/ + if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) + return this; // Reduced the amount of objects created return new ExtendsType(newType); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 31517891f..b7e5c60e5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -41,6 +41,8 @@ public class FunNType extends UnifyType { @Override public UnifyType setTypeParams(TypeParams newTp) { + if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) + return this; return getFunNType(newTp); } @@ -59,8 +61,8 @@ public class FunNType extends UnifyType { // TODO this bypasses the validation of the type parameters. // Wildcard types can be unified into FunNTypes. TypeParams newParams = typeParams.apply(unif); - /*if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) - return this;*/ + if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) + return this; return new FunNType(newParams); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index 9ffea7964..e82affe05 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -40,16 +40,16 @@ public final class ReferenceType extends UnifyType { UnifyType apply(Unifier unif) { TypeParams newParams = typeParams.apply(unif); - /*if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) - return this;*/ + if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams)) + return this; return new ReferenceType(new String(typeName), newParams); } @Override public UnifyType setTypeParams(TypeParams newTp) { - /*if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) - return this; // reduced the amount of objects created*/ + if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams)) + return this; // reduced the amount of objects created return new ReferenceType(new String(typeName), newTp); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index 664e16240..4f78602f5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -35,6 +35,9 @@ public final class SuperType extends WildcardType { */ @Override public UnifyType setTypeParams(TypeParams newTp) { + UnifyType newType = wildcardedType.setTypeParams(newTp); + if(newType == wildcardedType) + return this; // Reduced the amount of objects created return new SuperType(wildcardedType.setTypeParams(newTp)); } @@ -51,8 +54,8 @@ public final class SuperType extends WildcardType { @Override UnifyType apply(Unifier unif) { UnifyType newType = wildcardedType.apply(unif); - /*if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) - return this; // Reduced the amount of objects created*/ + if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType)) + return this; // Reduced the amount of objects created return new SuperType(newType); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java index f2336e966..02edb9332 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java @@ -30,7 +30,7 @@ public final class TypeParams implements Iterable{ typeParams[i] = types.get(i); // Hashcode calculation is expensive and must be cached. - hashCode = Arrays.hashCode(typeParams); + hashCode = Arrays.deepHashCode(typeParams); } /** @@ -41,7 +41,7 @@ public final class TypeParams implements Iterable{ typeParams = types; // Hashcode calculation is expensive and must be cached. - hashCode = Arrays.hashCode(typeParams); + hashCode = Arrays.deepHashCode(typeParams); } /** @@ -83,12 +83,12 @@ public final class TypeParams implements Iterable{ for(int i = 0; i < typeParams.length; i++) { UnifyType newType = typeParams[i].apply(unif); newParams[i] = newType; - //if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i]))) - //isNew = true; + if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i]))) + isNew = true; } - //if(!isNew) - // return this; + if(!isNew) + return this; return new TypeParams(newParams); } @@ -124,8 +124,8 @@ public final class TypeParams implements Iterable{ // Reduce the creation of new objects for less memory // Reduced the needed instances of TypeParams in the lambda14-Test from // 150.000 to 130.000 - /*if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx])) - return this;*/ + if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx])) + return this; UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length); newparams[idx] = t; return new TypeParams(newparams);