Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Remove List<T> tmp in AddKeepAlives (#8422
Browse files Browse the repository at this point in the history
)

Save some memory within `AddKeepAlivesStep.AddKeepAlives()` by
removing the `List<TypeDefinition>` temporary.  It is not necessary.
  • Loading branch information
Youssef1313 authored Oct 21, 2023
1 parent 2ff47e4 commit f84220a
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,25 @@ internal bool AddKeepAlives (AssemblyDefinition assembly)
return false;

bool changed = false;
List<TypeDefinition> types = assembly.MainModule.Types.ToList ();
foreach (TypeDefinition type in assembly.MainModule.Types)
AddNestedTypes (types, type);

foreach (TypeDefinition type in types)
if (MightNeedFix (type))
changed |= AddKeepAlives (type);
changed |= ProcessType (type);

return changed;
}

// Adapted from `MarkJavaObjects`
static void AddNestedTypes (List<TypeDefinition> types, TypeDefinition type)
bool ProcessType (TypeDefinition type)
{
if (!type.HasNestedTypes)
return;
bool changed = false;
if (MightNeedFix (type))
changed |= AddKeepAlives (type);

foreach (var t in type.NestedTypes) {
types.Add (t);
AddNestedTypes (types, t);
if (type.HasNestedTypes) {
foreach (var t in type.NestedTypes) {
changed |= ProcessType (t);
}
}

return changed;
}

bool MightNeedFix (TypeDefinition type)
Expand Down

0 comments on commit f84220a

Please sign in to comment.