Optimize COFFObjectFile::sectionContainsSymbol a bit.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Oct 2014 20:42:47 +0000 (20:42 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Oct 2014 20:42:47 +0000 (20:42 +0000)
There is no need to compute the coff_section of the symbol just to compare the
pointer.

Inspired by the ELF implementation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219233 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp

index bd7015713f925142d48b2eb854823d640dc47985..6e1f6832674bc104e92a790c0414babbffb48300 100644 (file)
@@ -347,13 +347,8 @@ std::error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
                                                       bool &Result) const {
   const coff_section *Sec = toSec(SecRef);
   COFFSymbolRef Symb = getCOFFSymbol(SymbRef);
-  const coff_section *SymbSec = nullptr;
-  if (std::error_code EC = getSection(Symb.getSectionNumber(), SymbSec))
-    return EC;
-  if (SymbSec == Sec)
-    Result = true;
-  else
-    Result = false;
+  int32_t SecNumber = (Sec - SectionTable) + 1;
+  Result = SecNumber == Symb.getSectionNumber();
   return object_error::success;
 }