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();
// Searches bindings for the controller and returns true if this binding is mapped somewhere in this controller
public bool HasBinding(string button)
{
return _bindings.SelectMany(kvp => kvp.Value).Any(boundButton => boundButton == button);
}
public bool HasBinding(string button) => _bindings.SelectMany(kvp => kvp.Value).Contains(button);
public void NormalizeFloats(IController controller)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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