Replace comparison of .Where().FirstOrDefault() to null with equivalent

This commit is contained in:
YoshiRulz 2019-03-27 14:17:09 +10:00
parent c82ff6077a
commit ac1b24ae6c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 9 additions and 16 deletions

View File

@ -140,14 +140,15 @@ namespace BizHawk.Client.Common
return false;
// weed out filesizes first to reduce the unnecessary overhead of a hashing operation
if (FirmwareDatabase.FirmwareFiles.Where(a => a.Size == fi.Length).FirstOrDefault() == null)
if (FirmwareDatabase.FirmwareFiles.All(a => a.Size != fi.Length))
return false;
// check the hash
using (var reader = new RealFirmwareReader())
{
reader.Read(fi);
if (FirmwareDatabase.FirmwareFiles.Where(a => a.Hash == reader.Dict.FirstOrDefault().Value.Hash).FirstOrDefault() != null)
var hash = reader.Dict.FirstOrDefault().Value.Hash;
if (FirmwareDatabase.FirmwareFiles.Any(a => a.Hash == hash))
return true;
}
}

View File

@ -475,20 +475,12 @@ namespace BizHawk.Client.Common
return Branches.IndexOf(branch);
}
public int BranchIndexByFrame(int frame)
{
TasBranch branch = Branches
.Where(b => b.Frame == frame)
.OrderByDescending(b => b.TimeStamp)
.FirstOrDefault();
if (branch == null)
{
return -1;
}
return Branches.IndexOf(branch);
}
public int BranchIndexByFrame(int frame) => Branches.Where(b => b.Frame == frame)
.Select((b, i) => new { Branch = b, Index = i }) // for sorting by element while remembering the index for returning
.OrderBy(o => o.Branch.TimeStamp) //TODO is this ordering necessary? method could be Branches.FindIndex(b => b.Frame == frame)
.LastOrDefault()
?.Index
?? -1;
public void AddBranch(TasBranch branch)
{