[PATCH] D32853: [ELF] - Speedup readAddressArea() implementation.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 03:02:30 PDT 2017


grimar updated this revision to Diff 97921.
grimar added a comment.

- Addressed review comment.


https://reviews.llvm.org/D32853

Files:
  ELF/SyntheticSections.cpp


Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1704,29 +1704,33 @@
   return Ret;
 }
 
-static InputSectionBase *findSection(ArrayRef<InputSectionBase *> Arr,
-                                     uint64_t Offset) {
-  for (InputSectionBase *S : Arr)
-    if (S && S != &InputSection::Discarded)
-      if (Offset >= S->getOffsetInFile() &&
-          Offset < S->getOffsetInFile() + S->getSize())
-        return S;
-  return nullptr;
-}
-
 static std::vector<AddressEntry>
 readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
   std::vector<AddressEntry> Ret;
 
+  std::vector<InputSectionBase *> V = Sec->File->getSections();
+  V.erase(llvm::remove_if(V,
+                          [](InputSectionBase *IS) {
+                            return !IS || IS == &InputSection::Discarded ||
+                                   !IS->getSize();
+                          }),
+          V.end());
+
   for (std::unique_ptr<DWARFCompileUnit> &CU : Dwarf.compile_units()) {
     DWARFAddressRangesVector Ranges;
     CU->collectAddressRanges(Ranges);
 
-    ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
-    for (std::pair<uint64_t, uint64_t> &R : Ranges)
-      if (InputSectionBase *S = findSection(Sections, R.first))
-        Ret.push_back({S, R.first - S->getOffsetInFile(),
-                       R.second - S->getOffsetInFile(), CurrentCU});
+    for (std::pair<uint64_t, uint64_t> &R : Ranges) {
+      auto I = std::lower_bound(V.begin(), V.end(), R.first,
+                                [](InputSectionBase *IS, uint64_t Offset) {
+                                  return IS->getOffsetInFile() < Offset;
+                                });
+      if (I == V.end())
+        continue;
+      InputSectionBase *IS = *I;
+      Ret.push_back({IS, R.first - IS->getOffsetInFile(),
+                     R.second - IS->getOffsetInFile(), CurrentCU});
+    }
     ++CurrentCU;
   }
   return Ret;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32853.97921.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170505/f28ee5f2/attachment.bin>


More information about the llvm-commits mailing list