[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
This commit is contained in:
parent
30ffb3e4fb
commit
0b49e503a5
@ -214,27 +214,29 @@ public:
|
||||
};
|
||||
|
||||
/// An iterator for Entries all having the same string as key.
|
||||
class ValueIterator {
|
||||
class SameNameIterator
|
||||
: public iterator_facade_base<SameNameIterator, std::forward_iterator_tag,
|
||||
Entry> {
|
||||
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<ValueIterator> equal_range(StringRef Key) const;
|
||||
iterator_range<SameNameIterator> equal_range(StringRef Key) const;
|
||||
};
|
||||
|
||||
/// .debug_names section consists of one or more units. Each unit starts with a
|
||||
|
||||
@ -305,15 +305,14 @@ std::optional<dwarf::Tag> 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<AppleAcceleratorTable::ValueIterator>
|
||||
iterator_range<AppleAcceleratorTable::SameNameIterator>
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user