Index: third_party/WebKit/Source/wtf/LinkedHashSet.h |
diff --git a/third_party/WebKit/Source/wtf/LinkedHashSet.h b/third_party/WebKit/Source/wtf/LinkedHashSet.h |
index d4bb0fbf02cdee762844acae5c7963d1475dbfc7..ba05506ad9001697cc84fe13f7fa6e5f9d5a3000 100644 |
--- a/third_party/WebKit/Source/wtf/LinkedHashSet.h |
+++ b/third_party/WebKit/Source/wtf/LinkedHashSet.h |
@@ -279,8 +279,10 @@ public: |
template<typename VisitorDispatcher> |
void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } |
- int64_t modifications() const { return m_impl.modifications(); } |
- void checkModifications(int64_t mods) const { m_impl.checkModifications(mods); } |
+#if ENABLE(ASSERT) |
+ void enterModificationForbiddenScope() { m_impl.enterModificationForbiddenScope(); } |
+ void leaveModificationForbiddenScope() { m_impl.leaveModificationForbiddenScope(); } |
+#endif |
private: |
Node* anchor() { return reinterpret_cast<Node*>(&m_anchor); } |
@@ -416,8 +418,7 @@ protected: |
LinkedHashSetConstIterator(const LinkedHashSetNodeBase* position, const LinkedHashSetType* container) |
: m_position(position) |
#if ENABLE(ASSERT) |
- , m_container(container) |
- , m_containerModifications(container->modifications()) |
+ , m_modificationForbiddenScope(position ? container : nullptr) |
#endif |
{ |
} |
@@ -425,7 +426,6 @@ protected: |
public: |
PointerType get() const |
{ |
- checkModifications(); |
return &static_cast<const Node*>(m_position)->m_value; |
} |
ReferenceType operator*() const { return *get(); } |
@@ -434,16 +434,28 @@ public: |
LinkedHashSetConstIterator& operator++() |
{ |
ASSERT(m_position); |
- checkModifications(); |
m_position = m_position->m_next; |
+#if ENABLE(ASSERT) |
+ // If now at the end, leave the forbidden scope. Waiting until |
+ // the iterator goes out of (stack) scope disallows perfectly valid |
+ // code idioms. |
+ if (!m_position) |
+ m_modificationForbiddenScope.leaveScope(); |
+#endif |
return *this; |
} |
LinkedHashSetConstIterator& operator--() |
{ |
ASSERT(m_position); |
- checkModifications(); |
m_position = m_position->m_prev; |
+#if ENABLE(ASSERT) |
+ // If now at the end, leave the forbidden scope. Waiting until |
+ // the iterator goes out of (stack) scope disallows perfectly valid |
+ // code idioms. |
+ if (!m_position) |
+ m_modificationForbiddenScope.leaveScope(); |
+#endif |
return *this; |
} |
@@ -460,16 +472,13 @@ public: |
} |
private: |
+ template<typename T, typename U, typename V, typename W> friend class LinkedHashSet; |
+ friend class LinkedHashSetIterator<LinkedHashSetType>; |
+ |
const LinkedHashSetNodeBase* m_position; |
#if ENABLE(ASSERT) |
- void checkModifications() const { m_container->checkModifications(m_containerModifications); } |
- const LinkedHashSetType* m_container; |
- int64_t m_containerModifications; |
-#else |
- void checkModifications() const { } |
+ HashTableModificationForbiddenScope<LinkedHashSetType> m_modificationForbiddenScope; |
#endif |
- template<typename T, typename U, typename V, typename W> friend class LinkedHashSet; |
- friend class LinkedHashSetIterator<LinkedHashSetType>; |
}; |
template<typename LinkedHashSetType> |