From 0b49e503a5bbd211fa445a1553f8a660e7bb0fb9 Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Mon, 12 Jun 2023 08:38:57 -0400 Subject: [PATCH] [nfc][AppleTables] Rename iterator We will soon need different kinds of iterators We also use one of LLVM's iterator classes to implement some basic iterator operations. Differential Revision: https://reviews.llvm.org/D153065 --- .../llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h | 22 ++++++++++++---------- llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 12 ++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h index a19a0fc..f9f9cc7 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h @@ -214,27 +214,29 @@ public: }; /// An iterator for Entries all having the same string as key. - class ValueIterator { + class SameNameIterator + : public iterator_facade_base { Entry Current; uint64_t Offset = 0; - void Next() { Offset += Current.Table.getHashDataEntryLength(); } - public: /// Construct a new iterator for the entries at \p DataOffset. - ValueIterator(const AppleAcceleratorTable &AccelTable, uint64_t DataOffset); + SameNameIterator(const AppleAcceleratorTable &AccelTable, + uint64_t DataOffset); const Entry &operator*() { uint64_t OffsetCopy = Offset; Current.extract(&OffsetCopy); return Current; } - ValueIterator &operator++() { Next(); return *this; } - friend bool operator==(const ValueIterator &A, const ValueIterator &B) { - return A.Offset == B.Offset; + SameNameIterator &operator++() { + Offset += Current.Table.getHashDataEntryLength(); + return *this; } - friend bool operator!=(const ValueIterator &A, const ValueIterator &B) { - return !(A == B); + friend bool operator==(const SameNameIterator &A, + const SameNameIterator &B) { + return A.Offset == B.Offset; } }; @@ -268,7 +270,7 @@ public: void dump(raw_ostream &OS) const override; /// Look up all entries in the accelerator table matching \c Key. - iterator_range equal_range(StringRef Key) const; + iterator_range equal_range(StringRef Key) const; }; /// .debug_names section consists of one or more units. Each unit starts with a diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index 03bc8a8..3e052f2 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -305,15 +305,14 @@ std::optional AppleAcceleratorTable::Entry::getTag() const { return std::nullopt; } -AppleAcceleratorTable::ValueIterator::ValueIterator( +AppleAcceleratorTable::SameNameIterator::SameNameIterator( const AppleAcceleratorTable &AccelTable, uint64_t DataOffset) - : Current(AccelTable), Offset(DataOffset) { -} + : Current(AccelTable), Offset(DataOffset) {} -iterator_range +iterator_range AppleAcceleratorTable::equal_range(StringRef Key) const { const auto EmptyRange = - make_range(ValueIterator(*this, 0), ValueIterator(*this, 0)); + make_range(SameNameIterator(*this, 0), SameNameIterator(*this, 0)); if (!IsValid) return EmptyRange; @@ -341,7 +340,8 @@ AppleAcceleratorTable::equal_range(StringRef Key) const { return EmptyRange; uint64_t EndOffset = DataOffset + *NumEntries * getHashDataEntryLength(); if (Key == *MaybeStr) - return make_range({*this, DataOffset}, ValueIterator{*this, EndOffset}); + return make_range({*this, DataOffset}, + SameNameIterator{*this, EndOffset}); DataOffset = EndOffset; StrOffset = readStringOffsetAt(DataOffset); } -- 2.7.4