From 1ff0a0ffaf70cd8f72e80650de184276add24148 Mon Sep 17 00:00:00 2001 From: Washi Date: Sat, 17 Sep 2022 17:35:31 +0200 Subject: [PATCH] Replace LINQ code with for loop in GetSectionContaining[Rva|Offset] --- src/AsmResolver.PE.File/PEFile.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/AsmResolver.PE.File/PEFile.cs b/src/AsmResolver.PE.File/PEFile.cs index 56cf6999d..26bb6e1fe 100644 --- a/src/AsmResolver.PE.File/PEFile.cs +++ b/src/AsmResolver.PE.File/PEFile.cs @@ -216,8 +216,19 @@ public PESection GetSectionContainingOffset(ulong fileOffset) /// true if the section was found, false otherwise. 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; } /// @@ -231,8 +242,19 @@ public PESection GetSectionContainingRva(uint rva) /// 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; } ///