Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: Source/wtf/LinkedHashSet.h

Issue 474943002: Fix for LinkedHashSet::swap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: templated test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/wtf/ListHashSetTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/LinkedHashSet.h
diff --git a/Source/wtf/LinkedHashSet.h b/Source/wtf/LinkedHashSet.h
index 19c4ff3a586c5a78d14331fa14ef0ef0b7282f3c..b0a5859285fb5b8eb014a7a96f674da823798925 100644
--- a/Source/wtf/LinkedHashSet.h
+++ b/Source/wtf/LinkedHashSet.h
@@ -499,7 +499,7 @@ template<typename T, typename U, typename V, typename W>
inline void LinkedHashSet<T, U, V, W>::swap(LinkedHashSet& other)
{
m_impl.swap(other.m_impl);
- swap(m_anchor, other.m_anchor);
+ swapAnchor(m_anchor, other.m_anchor);
}
template<typename T, typename U, typename V, typename Allocator>
@@ -667,8 +667,32 @@ inline void LinkedHashSet<T, U, V, W>::remove(ValuePeekInType value)
remove(find(value));
}
+inline void swapAnchor(LinkedHashSetNodeBase& a, LinkedHashSetNodeBase& b)
+{
+ ASSERT(a.m_prev && a.m_next && b.m_prev && b.m_next);
+ swap(a.m_prev, b.m_prev);
+ swap(a.m_next, b.m_next);
+ if (b.m_next == &a) {
+ ASSERT(b.m_prev == &a);
+ b.m_next = &b;
+ b.m_prev = &b;
+ } else {
+ b.m_next->m_prev = &b;
+ b.m_prev->m_next = &b;
+ }
+ if (a.m_next == &b) {
+ ASSERT(a.m_prev == &b);
+ a.m_next = &a;
+ a.m_prev = &a;
+ } else {
+ a.m_next->m_prev = &a;
+ a.m_prev->m_next = &a;
+ }
+}
+
inline void swap(LinkedHashSetNodeBase& a, LinkedHashSetNodeBase& b)
{
+ ASSERT(a.m_next != &a && b.m_next != &b);
swap(a.m_prev, b.m_prev);
swap(a.m_next, b.m_next);
if (b.m_next) {
« no previous file with comments | « no previous file | Source/wtf/ListHashSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698