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; return false;
// weed out filesizes first to reduce the unnecessary overhead of a hashing operation // 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; return false;
// check the hash // check the hash
using (var reader = new RealFirmwareReader()) using (var reader = new RealFirmwareReader())
{ {
reader.Read(fi); 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; return true;
} }
} }

View File

@ -475,20 +475,12 @@ namespace BizHawk.Client.Common
return Branches.IndexOf(branch); return Branches.IndexOf(branch);
} }
public int BranchIndexByFrame(int frame) 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
TasBranch branch = Branches .OrderBy(o => o.Branch.TimeStamp) //TODO is this ordering necessary? method could be Branches.FindIndex(b => b.Frame == frame)
.Where(b => b.Frame == frame) .LastOrDefault()
.OrderByDescending(b => b.TimeStamp) ?.Index
.FirstOrDefault(); ?? -1;
if (branch == null)
{
return -1;
}
return Branches.IndexOf(branch);
}
public void AddBranch(TasBranch branch) public void AddBranch(TasBranch branch)
{ {