Simplify Any calls

Replace .Where(pred).Any() with .Any(pred)
Replace .Any(x => x == y) with .Contains(y)
This commit is contained in:
YoshiRulz 2019-03-25 04:02:11 +10:00
parent 718e60cbc4
commit 2900484ad5
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
8 changed files with 14 additions and 32 deletions

View File

@ -65,10 +65,7 @@ namespace BizHawk.Client.Common
.ToList(); .ToList();
// Searches bindings for the controller and returns true if this binding is mapped somewhere in this controller // Searches bindings for the controller and returns true if this binding is mapped somewhere in this controller
public bool HasBinding(string button) public bool HasBinding(string button) => _bindings.SelectMany(kvp => kvp.Value).Contains(button);
{
return _bindings.SelectMany(kvp => kvp.Value).Any(boundButton => boundButton == button);
}
public void NormalizeFloats(IController controller) public void NormalizeFloats(IController controller)
{ {

View File

@ -484,10 +484,7 @@ namespace BizHawk.Client.Common
/// used for the current <see cref="Watch"/> /// used for the current <see cref="Watch"/>
/// </summary> /// </summary>
/// <param name="type"><see cref="DisplayType"/> you want to check</param> /// <param name="type"><see cref="DisplayType"/> you want to check</param>
public bool IsDiplayTypeAvailable(DisplayType type) public bool IsDiplayTypeAvailable(DisplayType type) => AvailableTypes().Contains(type);
{
return AvailableTypes().Any(d => d == type);
}
/// <summary> /// <summary>
/// Transforms the current instance into a string /// Transforms the current instance into a string

View File

@ -667,17 +667,17 @@ namespace BizHawk.Client.EmuHawk
switch (size) switch (size)
{ {
case WatchSize.Byte: case WatchSize.Byte:
isTypeCompatible = ByteWatch.ValidTypes.Any(t => t == _settings.Type); isTypeCompatible = ByteWatch.ValidTypes.Contains(_settings.Type);
SizeDropdown.SelectedIndex = 0; SizeDropdown.SelectedIndex = 0;
break; break;
case WatchSize.Word: case WatchSize.Word:
isTypeCompatible = WordWatch.ValidTypes.Any(t => t == _settings.Type); isTypeCompatible = WordWatch.ValidTypes.Contains(_settings.Type);
SizeDropdown.SelectedIndex = 1; SizeDropdown.SelectedIndex = 1;
break; break;
case WatchSize.DWord: case WatchSize.DWord:
isTypeCompatible = DWordWatch.ValidTypes.Any(t => t == _settings.Type); isTypeCompatible = DWordWatch.ValidTypes.Contains(_settings.Type);
SizeDropdown.SelectedIndex = 2; SizeDropdown.SelectedIndex = 2;
break; break;
} }

View File

@ -41,15 +41,15 @@ namespace BizHawk.Client.EmuHawk
switch (value) switch (value)
{ {
case WatchSize.Byte: case WatchSize.Byte:
isTypeCompatible = ByteWatch.ValidTypes.Any(t => t == _type); isTypeCompatible = ByteWatch.ValidTypes.Contains(_type);
break; break;
case WatchSize.Word: case WatchSize.Word:
isTypeCompatible = WordWatch.ValidTypes.Any(t => t == _type); isTypeCompatible = WordWatch.ValidTypes.Contains(_type);
break; break;
case WatchSize.DWord: case WatchSize.DWord:
isTypeCompatible = DWordWatch.ValidTypes.Any(t => t == _type); isTypeCompatible = DWordWatch.ValidTypes.Contains(_type);
break; break;
} }

View File

@ -50,10 +50,7 @@ namespace BizHawk.Common.NumberExtensions
return (b & (1 << index)) != 0; return (b & (1 << index)) != 0;
} }
public static bool In(this int i, params int[] options) public static bool In(this int i, params int[] options) => options.Contains(i);
{
return options.Any(j => i == j);
}
public static byte BinToBCD(this byte v) public static byte BinToBCD(this byte v)
{ {

View File

@ -108,20 +108,11 @@ namespace BizHawk.Emulation.Common
public bool HasExecutes => _hasExecutes; public bool HasExecutes => _hasExecutes;
public bool HasReadsForScope(string scope) public bool HasReadsForScope(string scope) => _reads.Any(e => e.Scope == scope);
{
return _reads.Where(e => e.Scope == scope).Any();
}
public bool HasWritesForScope(string scope) public bool HasWritesForScope(string scope) => _writes.Any(e => e.Scope == scope);
{
return _writes.Where(e => e.Scope == scope).Any();
}
public bool HasExecutesForScope(string scope) public bool HasExecutesForScope(string scope) => _execs.Any(e => e.Scope == scope);
{
return _execs.Where(e => e.Scope == scope).Any();
}
private bool UpdateHasVariables() private bool UpdateHasVariables()
{ {

View File

@ -92,7 +92,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
foreach (var key in _machine.CPC.AmstradCPCControllerDefinition.BoolButtons) foreach (var key in _machine.CPC.AmstradCPCControllerDefinition.BoolButtons)
{ {
if (!KeyboardMatrix.Any(s => s == key)) if (!KeyboardMatrix.Contains(key))
nonMatrix.Add(key); nonMatrix.Add(key);
} }

View File

@ -69,7 +69,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
foreach (var key in _machine.Spectrum.ZXSpectrumControllerDefinition.BoolButtons) foreach (var key in _machine.Spectrum.ZXSpectrumControllerDefinition.BoolButtons)
{ {
if (!KeyboardMatrix.Any(s => s == key)) if (!KeyboardMatrix.Contains(key))
nonMatrix.Add(key); nonMatrix.Add(key);
} }