Avoid delegate allocation in RotationPaletteEffect.

Use a loop to perform the same check instead.
This commit is contained in:
RoosterDragon
2017-01-11 21:38:40 +00:00
parent 2239d6c88e
commit d1cc546f8d

View File

@@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.Traits
foreach (var kvp in palettes)
{
if ((info.Palettes.Count > 0 && !info.Palettes.Any(kvp.Key.StartsWith))
|| (info.ExcludePalettes.Count > 0 && info.ExcludePalettes.Any(kvp.Key.StartsWith)))
if ((info.Palettes.Count > 0 && !AnyPaletteNameStartsWith(info.Palettes, kvp.Key))
|| (info.ExcludePalettes.Count > 0 && AnyPaletteNameStartsWith(info.ExcludePalettes, kvp.Key)))
continue;
var palette = kvp.Value;
@@ -105,5 +105,15 @@ namespace OpenRA.Mods.Common.Traits
palette[info.RotationBase + i] = rotationBuffer[i];
}
}
static bool AnyPaletteNameStartsWith(HashSet<string> names, string prefix)
{
// PERF: Avoid LINQ.
foreach (var name in names)
if (name.StartsWith(prefix))
return true;
return false;
}
}
}