memory optimization
This commit is contained in:
parent
bb8df92cba
commit
7b6b720b57
@ -29,6 +29,9 @@ public final class ExtendsType extends WildcardType {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UnifyType setTypeParams(TypeParams newTp) {
|
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));
|
return new ExtendsType(wildcardedType.setTypeParams(newTp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +48,8 @@ public final class ExtendsType extends WildcardType {
|
|||||||
@Override
|
@Override
|
||||||
UnifyType apply(Unifier unif) {
|
UnifyType apply(Unifier unif) {
|
||||||
UnifyType newType = wildcardedType.apply(unif);
|
UnifyType newType = wildcardedType.apply(unif);
|
||||||
/*if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType))
|
if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType))
|
||||||
return this; // Reduced the amount of objects created*/
|
return this; // Reduced the amount of objects created
|
||||||
return new ExtendsType(newType);
|
return new ExtendsType(newType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ public class FunNType extends UnifyType {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UnifyType setTypeParams(TypeParams newTp) {
|
public UnifyType setTypeParams(TypeParams newTp) {
|
||||||
|
if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams))
|
||||||
|
return this;
|
||||||
return getFunNType(newTp);
|
return getFunNType(newTp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +61,8 @@ public class FunNType extends UnifyType {
|
|||||||
// TODO this bypasses the validation of the type parameters.
|
// TODO this bypasses the validation of the type parameters.
|
||||||
// Wildcard types can be unified into FunNTypes.
|
// Wildcard types can be unified into FunNTypes.
|
||||||
TypeParams newParams = typeParams.apply(unif);
|
TypeParams newParams = typeParams.apply(unif);
|
||||||
/*if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams))
|
if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams))
|
||||||
return this;*/
|
return this;
|
||||||
|
|
||||||
return new FunNType(newParams);
|
return new FunNType(newParams);
|
||||||
}
|
}
|
||||||
|
@ -40,16 +40,16 @@ public final class ReferenceType extends UnifyType {
|
|||||||
UnifyType apply(Unifier unif) {
|
UnifyType apply(Unifier unif) {
|
||||||
TypeParams newParams = typeParams.apply(unif);
|
TypeParams newParams = typeParams.apply(unif);
|
||||||
|
|
||||||
/*if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams))
|
if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams))
|
||||||
return this;*/
|
return this;
|
||||||
|
|
||||||
return new ReferenceType(new String(typeName), newParams);
|
return new ReferenceType(new String(typeName), newParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UnifyType setTypeParams(TypeParams newTp) {
|
public UnifyType setTypeParams(TypeParams newTp) {
|
||||||
/*if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams))
|
if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams))
|
||||||
return this; // reduced the amount of objects created*/
|
return this; // reduced the amount of objects created
|
||||||
return new ReferenceType(new String(typeName), newTp);
|
return new ReferenceType(new String(typeName), newTp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ public final class SuperType extends WildcardType {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UnifyType setTypeParams(TypeParams newTp) {
|
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));
|
return new SuperType(wildcardedType.setTypeParams(newTp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +54,8 @@ public final class SuperType extends WildcardType {
|
|||||||
@Override
|
@Override
|
||||||
UnifyType apply(Unifier unif) {
|
UnifyType apply(Unifier unif) {
|
||||||
UnifyType newType = wildcardedType.apply(unif);
|
UnifyType newType = wildcardedType.apply(unif);
|
||||||
/*if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType))
|
if(newType.hashCode() == wildcardedType.hashCode() && newType.equals(wildcardedType))
|
||||||
return this; // Reduced the amount of objects created*/
|
return this; // Reduced the amount of objects created
|
||||||
return new SuperType(newType);
|
return new SuperType(newType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public final class TypeParams implements Iterable<UnifyType>{
|
|||||||
typeParams[i] = types.get(i);
|
typeParams[i] = types.get(i);
|
||||||
|
|
||||||
// Hashcode calculation is expensive and must be cached.
|
// 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;
|
typeParams = types;
|
||||||
|
|
||||||
// Hashcode calculation is expensive and must be cached.
|
// 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++) {
|
for(int i = 0; i < typeParams.length; i++) {
|
||||||
UnifyType newType = typeParams[i].apply(unif);
|
UnifyType newType = typeParams[i].apply(unif);
|
||||||
newParams[i] = newType;
|
newParams[i] = newType;
|
||||||
//if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i])))
|
if(!isNew && (newType.hashCode() != typeParams[i].hashCode() || !newType.equals(typeParams[i])))
|
||||||
//isNew = true;
|
isNew = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(!isNew)
|
if(!isNew)
|
||||||
// return this;
|
return this;
|
||||||
return new TypeParams(newParams);
|
return new TypeParams(newParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +124,8 @@ public final class TypeParams implements Iterable<UnifyType>{
|
|||||||
// Reduce the creation of new objects for less memory
|
// Reduce the creation of new objects for less memory
|
||||||
// Reduced the needed instances of TypeParams in the lambda14-Test from
|
// Reduced the needed instances of TypeParams in the lambda14-Test from
|
||||||
// 150.000 to 130.000
|
// 150.000 to 130.000
|
||||||
/*if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx]))
|
if(t.hashCode() == typeParams[idx].hashCode() && t.equals(typeParams[idx]))
|
||||||
return this;*/
|
return this;
|
||||||
UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length);
|
UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length);
|
||||||
newparams[idx] = t;
|
newparams[idx] = t;
|
||||||
return new TypeParams(newparams);
|
return new TypeParams(newparams);
|
||||||
|
Loading…
Reference in New Issue
Block a user