Simplify the handling of iterators in ObjectFile.
None of the object file formats reported error on iterator increment. In
retrospect, that is not too surprising: no object format stores symbols or
sections in a linked list or other structure that requires chasing pointers.
As a consequence, all error checking can be done on begin() and end().
This reduces the text segment of bin/llvm-readobj in my machine from 521233 to
518526 bytes.
llvm-svn: 200442
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index 1558d9d..6439056 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -87,13 +87,10 @@
return Addr;
}
-error_code COFFObjectFile::getSymbolNext(DataRefImpl Ref,
- SymbolRef &Result) const {
+void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
const coff_symbol *Symb = toSymb(Ref);
Symb += 1 + Symb->NumberOfAuxSymbols;
Ref.p = reinterpret_cast<uintptr_t>(Symb);
- Result = SymbolRef(Ref, this);
- return object_error::success;
}
error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
@@ -221,13 +218,10 @@
report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
}
-error_code COFFObjectFile::getSectionNext(DataRefImpl Ref,
- SectionRef &Result) const {
+void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
const coff_section *Sec = toSec(Ref);
Sec += 1;
Ref.p = reinterpret_cast<uintptr_t>(Sec);
- Result = SectionRef(Ref, this);
- return object_error::success;
}
error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
@@ -386,11 +380,8 @@
// Returns the file offset for the given RVA.
error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
- error_code EC;
for (section_iterator I = begin_sections(), E = end_sections(); I != E;
- I.increment(EC)) {
- if (EC)
- return EC;
+ ++I) {
const coff_section *Section = getCOFFSection(I);
uint32_t SectionStart = Section->VirtualAddress;
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
@@ -801,12 +792,9 @@
return reinterpret_cast<const coff_relocation*>(Rel.p);
}
-error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
- RelocationRef &Res) const {
+void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
Rel.p = reinterpret_cast<uintptr_t>(
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
- Res = RelocationRef(Rel, this);
- return object_error::success;
}
error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
@@ -932,10 +920,8 @@
return ImportTable == Other.ImportTable && Index == Other.Index;
}
-error_code
-ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
- Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
- return object_error::success;
+void ImportDirectoryEntryRef::moveNext() {
+ ++Index;
}
error_code ImportDirectoryEntryRef::
@@ -967,10 +953,8 @@
return ExportTable == Other.ExportTable && Index == Other.Index;
}
-error_code
-ExportDirectoryEntryRef::getNext(ExportDirectoryEntryRef &Result) const {
- Result = ExportDirectoryEntryRef(ExportTable, Index + 1, OwningObject);
- return object_error::success;
+void ExportDirectoryEntryRef::moveNext() {
+ ++Index;
}
// Returns the name of the current export symbol. If the symbol is exported only