From d1cc546f8dc722353a8a37467bf715389fdf9979 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Wed, 11 Jan 2017 21:38:40 +0000 Subject: [PATCH] Avoid delegate allocation in RotationPaletteEffect. Use a loop to perform the same check instead. --- .../Traits/PaletteEffects/RotationPaletteEffect.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index 21ba9a0419..258f89f358 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -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 names, string prefix) + { + // PERF: Avoid LINQ. + foreach (var name in names) + if (name.StartsWith(prefix)) + return true; + + return false; + } } }