Skip to content

Commit

Permalink
Replace LINQ code with for loop in GetSectionContaining[Rva|Offset]
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Sep 17, 2022
1 parent 751141f commit 1ff0a0f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/AsmResolver.PE.File/PEFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,19 @@ public PESection GetSectionContainingOffset(ulong fileOffset)
/// <returns><c>true</c> if the section was found, <c>false</c> otherwise.</returns>
public bool TryGetSectionContainingOffset(ulong fileOffset, [NotNullWhen(true)] out PESection? section)
{
section = Sections.FirstOrDefault(s => s.ContainsFileOffset(fileOffset));
return section != null;
var sections = Sections;

for (int i = 0; i < sections.Count; i++)
{
if (sections[i].ContainsFileOffset(fileOffset))
{
section = sections[i];
return true;
}
}

section = null;
return false;
}

/// <inheritdoc />
Expand All @@ -231,8 +242,19 @@ public PESection GetSectionContainingRva(uint rva)
/// <inheritdoc />
public bool TryGetSectionContainingRva(uint rva, [NotNullWhen(true)] out PESection? section)
{
section = Sections.FirstOrDefault(s => s.ContainsRva(rva));
return section != null;
var sections = Sections;

for (int i = 0; i < sections.Count; i++)
{
if (sections[i].ContainsRva(rva))
{
section = sections[i];
return true;
}
}

section = null;
return false;
}

/// <inheritdoc />
Expand Down

0 comments on commit 1ff0a0f

Please sign in to comment.