mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-09 04:25:38 +00:00
Bug 1617084 - Return nullptr_t instead of a full iterator from end(). r=bzbarsky
This is legal with C++17. It's not too important for the ancestor iterators because they're just a pointer anyway, but it's nice for ShadowIncludingTreeIterator, which has an AutoTArray and what not. Depends on D63594 Differential Revision: https://phabricator.services.mozilla.com/D64355 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
86f020c44b
commit
489c535384
@ -38,17 +38,14 @@ namespace dom {
|
||||
explicit Inclusive##name_(const nsINode& aNode) \
|
||||
: mCurrent(const_cast<nsINode*>(&aNode)) {} \
|
||||
Self& begin() { return *this; } \
|
||||
Self end() { return {}; } \
|
||||
bool operator!=(const Self& aOther) const { \
|
||||
return mCurrent != aOther.mCurrent; \
|
||||
} \
|
||||
std::nullptr_t end() const { return nullptr; } \
|
||||
bool operator!=(std::nullptr_t) const { return !!mCurrent; } \
|
||||
void operator++() { mCurrent = mCurrent->method_(); } \
|
||||
nsINode* operator*() { return mCurrent; } \
|
||||
\
|
||||
MUTATION_GUARD(Inclusive##name_) \
|
||||
\
|
||||
protected: \
|
||||
Inclusive##name_() : mCurrent(nullptr) {} \
|
||||
explicit Inclusive##name_(nsINode* aCurrent) : mCurrent(aCurrent) {} \
|
||||
nsINode* mCurrent; \
|
||||
}; \
|
||||
|
@ -24,6 +24,7 @@ class FilteredNodeIterator : public Iter {
|
||||
}
|
||||
|
||||
FilteredNodeIterator& begin() { return *this; }
|
||||
using Iter::end;
|
||||
|
||||
void operator++() {
|
||||
Iter::operator++();
|
||||
@ -31,14 +32,13 @@ class FilteredNodeIterator : public Iter {
|
||||
}
|
||||
|
||||
using Iter::operator!=;
|
||||
|
||||
T* operator*() {
|
||||
nsINode* node = Iter::operator*();
|
||||
MOZ_ASSERT(!node || T::FromNode(node));
|
||||
return static_cast<T*>(node);
|
||||
}
|
||||
|
||||
FilteredNodeIterator end() { return FilteredNodeIterator(); }
|
||||
|
||||
private:
|
||||
void EnsureValid() {
|
||||
while (true) {
|
||||
|
@ -45,20 +45,15 @@ class ShadowIncludingTreeIterator {
|
||||
// it goes.
|
||||
ShadowIncludingTreeIterator& begin() { return *this; }
|
||||
|
||||
ShadowIncludingTreeIterator end() { return ShadowIncludingTreeIterator(); }
|
||||
std::nullptr_t end() const { return nullptr; }
|
||||
|
||||
bool operator!=(const ShadowIncludingTreeIterator& aOther) {
|
||||
return mCurrent != aOther.mCurrent;
|
||||
}
|
||||
bool operator!=(std::nullptr_t) const { return !!mCurrent; }
|
||||
|
||||
void operator++() { Next(); }
|
||||
|
||||
nsINode* operator*() { return mCurrent; }
|
||||
|
||||
private:
|
||||
// Constructor used only for end() to represent a drained iterator.
|
||||
ShadowIncludingTreeIterator() : mCurrent(nullptr) {}
|
||||
|
||||
void Next() {
|
||||
MOZ_ASSERT(mCurrent, "Don't call Next() after we have no current node");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user