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 --- include/llvm/Object/MachO.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'include/llvm/Object/MachO.h') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 731a07be60..fb548e3262 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -38,7 +38,7 @@ public: bool operator==(const DiceRef &Other) const; bool operator<(const DiceRef &Other) const; - error_code getNext(DiceRef &Result) const; + void moveNext(); error_code getOffset(uint32_t &Result) const; error_code getLength(uint16_t &Result) const; @@ -59,8 +59,7 @@ public: MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, error_code &EC, bool BufferOwned = true); - error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const - LLVM_OVERRIDE; + void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE; error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const LLVM_OVERRIDE; error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const @@ -79,8 +78,7 @@ public: error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const LLVM_OVERRIDE; - error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const - LLVM_OVERRIDE; + void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE; error_code getSectionName(DataRefImpl Sec, StringRef &Res) const LLVM_OVERRIDE; error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const @@ -104,8 +102,7 @@ public: relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE; relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE; - error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const - LLVM_OVERRIDE; + void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE; error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const LLVM_OVERRIDE; error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const @@ -244,13 +241,10 @@ inline bool DiceRef::operator<(const DiceRef &Other) const { return DicePimpl < Other.DicePimpl; } -inline error_code DiceRef::getNext(DiceRef &Result) const { - DataRefImpl Rel = DicePimpl; +inline void DiceRef::moveNext() { const MachO::data_in_code_entry *P = - reinterpret_cast(Rel.p); - Rel.p = reinterpret_cast(P + 1); - Result = DiceRef(Rel, OwningObject); - return object_error::success; + reinterpret_cast(DicePimpl.p); + DicePimpl.p = reinterpret_cast(P + 1); } // Since a Mach-O data in code reference, a DiceRef, can only be created when -- cgit v1.2.3