From efdbec8b0a49fb67c3844be703548fdc6c1dded0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 30 Jan 2014 02:49:50 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/COFFObjectFile.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'lib/Object/COFFObjectFile.cpp') diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 1558d9d15f..6439056dfa 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -87,13 +87,10 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const { 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(Symb); - Result = SymbolRef(Ref, this); - return object_error::success; } error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, @@ -221,13 +218,10 @@ error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref, 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(Sec); - Result = SectionRef(Ref, this); - return object_error::success; } error_code COFFObjectFile::getSectionName(DataRefImpl Ref, @@ -386,11 +380,8 @@ error_code COFFObjectFile::initSymbolTablePtr() { // 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 @@ const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const { return reinterpret_cast(Rel.p); } -error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const { +void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { Rel.p = reinterpret_cast( reinterpret_cast(Rel.p) + 1); - Res = RelocationRef(Rel, this); - return object_error::success; } error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, @@ -932,10 +920,8 @@ operator==(const ImportDirectoryEntryRef &Other) const { 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 @@ operator==(const ExportDirectoryEntryRef &Other) const { 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 -- cgit v1.2.3