memory optimization
This commit is contained in:
parent
bb8df92cba
commit
7b6b720b57
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public final class TypeParams implements Iterable<UnifyType>{
|
||||
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<UnifyType>{
|
||||
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<UnifyType>{
|
||||
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<UnifyType>{
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user