[llvm] r242715 - Simplify now that we can iterate backwards. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 20 14:45:57 PDT 2015
Author: rafael
Date: Mon Jul 20 16:45:56 2015
New Revision: 242715
URL: http://llvm.org/viewvc/llvm-project?rev=242715&view=rev
Log:
Simplify now that we can iterate backwards. NFC.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=242715&r1=242714&r2=242715&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jul 20 16:45:56 2015
@@ -282,11 +282,9 @@ public:
}
const Elf_Dyn *dynamic_table_begin() const;
- /// \param NULLEnd use one past the first DT_NULL entry as the end instead of
- /// the section size.
- const Elf_Dyn *dynamic_table_end(bool NULLEnd = false) const;
- Elf_Dyn_Range dynamic_table(bool NULLEnd = false) const {
- return make_range(dynamic_table_begin(), dynamic_table_end(NULLEnd));
+ const Elf_Dyn *dynamic_table_end() const;
+ Elf_Dyn_Range dynamic_table() const {
+ return make_range(dynamic_table_begin(), dynamic_table_end());
}
const Elf_Sym *dynamic_symbol_begin() const {
@@ -818,24 +816,12 @@ ELFFile<ELFT>::dynamic_table_begin() con
template <class ELFT>
const typename ELFFile<ELFT>::Elf_Dyn *
-ELFFile<ELFT>::dynamic_table_end(bool NULLEnd) const {
+ELFFile<ELFT>::dynamic_table_end() const {
uint64_t Size = DynamicRegion.Size;
if (Size % sizeof(Elf_Dyn))
report_fatal_error("Invalid dynamic table size");
- const Elf_Dyn *Ret = dynamic_table_begin() + Size / sizeof(Elf_Dyn);
-
- if (NULLEnd) {
- const Elf_Dyn *Start = dynamic_table_begin();
- while (Start != Ret && Start->getTag() != ELF::DT_NULL)
- ++Start;
-
- // Include the DT_NULL.
- if (Start != Ret)
- ++Start;
- Ret = Start;
- }
- return Ret;
+ return dynamic_table_begin() + Size / sizeof(Elf_Dyn);
}
template <class ELFT>
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=242715&r1=242714&r2=242715&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Mon Jul 20 16:45:56 2015
@@ -1052,9 +1052,20 @@ template <> void ELFDumper<ELFType<suppo
template<class ELFT>
void ELFDumper<ELFT>::printDynamicTable() {
- auto DynTable = Obj->dynamic_table(true);
+ auto I = Obj->dynamic_table_begin();
+ auto E = Obj->dynamic_table_end();
- ptrdiff_t Total = std::distance(DynTable.begin(), DynTable.end());
+ if (I == E)
+ return;
+
+ --E;
+ while (I != E && E->getTag() == ELF::DT_NULL)
+ --E;
+ if (E->getTag() != ELF::DT_NULL)
+ ++E;
+ ++E;
+
+ ptrdiff_t Total = std::distance(I, E);
if (Total == 0)
return;
@@ -1066,7 +1077,9 @@ void ELFDumper<ELFT>::printDynamicTable(
W.startLine()
<< " Tag" << (Is64 ? " " : " ") << "Type"
<< " " << "Name/Value\n";
- for (const auto &Entry : DynTable) {
+ while (I != E) {
+ const typename ELFO::Elf_Dyn &Entry = *I;
+ ++I;
W.startLine()
<< " "
<< format(Is64 ? "0x%016" PRIX64 : "0x%08" PRIX64, Entry.getTag())
More information about the llvm-commits
mailing list