remove some redundant SelectableInfo lookups

This commit is contained in:
Chris Forbes
2011-10-23 11:49:33 +13:00
parent eebfb34ea2
commit aef3ff6e65

View File

@@ -117,13 +117,15 @@ namespace OpenRA
public static bool HasVoice(this Actor a) public static bool HasVoice(this Actor a)
{ {
return a.Info.Traits.Contains<SelectableInfo>() && a.Info.Traits.Get<SelectableInfo>().Voice != null; var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
return selectable != null && selectable.Voice != null;
} }
public static VoiceInfo GetVoice(this Actor a) public static VoiceInfo GetVoice(this Actor a)
{ {
if (!a.Info.Traits.Contains<SelectableInfo>()) return null; var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
var v = a.Info.Traits.Get<SelectableInfo>().Voice; if (selectable == null) return null;
var v = selectable.Voice;
return (v == null) ? null : Rules.Voices[v]; return (v == null) ? null : Rules.Voices[v];
} }