The following is the code for a method of an object that maintains a list of types (IType[] types
) in an array as well as a field that stores the number of non-null types in the array (int typeCount
). What the method should do is to resolve
all types in the list (resolve
either returns the type it was called at or another IType
). I am now wondering which of the following implementations is better:
for (int i = 0; i < this.typeCount; i++)
{
this.types[i] = this.types[i].resolve(markers, context);
// vs
IType t1 = this.types[i];
IType t2 = t1.resolve(markers, context);
if (t1 != t2)
{
this.types[i] = t2;
}
}
Note that this pattern occurs in many places throughout the project, of which many can be considered boilerplate.