Replace comparison of .Where().FirstOrDefault() to null with equivalent
This commit is contained in:
parent
c82ff6077a
commit
ac1b24ae6c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue