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

Unified Diff: third_party/WebKit/Source/wtf/DequeTest.cpp

Issue 1846473002: WTF: Implement move of Deques. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « third_party/WebKit/Source/wtf/Deque.h ('k') | third_party/WebKit/Source/wtf/HashMapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/DequeTest.cpp
diff --git a/third_party/WebKit/Source/wtf/DequeTest.cpp b/third_party/WebKit/Source/wtf/DequeTest.cpp
index 6ab94e183a531c093262d995b85b6423dab99fc9..83c00e479558017b49b53da35ad34aa0026993d7 100644
--- a/third_party/WebKit/Source/wtf/DequeTest.cpp
+++ b/third_party/WebKit/Source/wtf/DequeTest.cpp
@@ -566,6 +566,46 @@ TEST(DequeTest, UniquePtr)
deque.clear();
}
+class CountCopy final {
+public:
+ explicit CountCopy(int* counter = nullptr) : m_counter(counter) { }
+ CountCopy(const CountCopy& other)
+ : m_counter(other.m_counter)
+ {
+ if (m_counter)
+ ++*m_counter;
+ }
+ CountCopy& operator=(const CountCopy& other)
+ {
+ m_counter = other.m_counter;
+ if (m_counter)
+ ++*m_counter;
+ return *this;
+ }
+
+private:
+ int* m_counter;
+};
+
+TEST(DequeTest, MoveShouldNotMakeCopy)
+{
+ // Because data in inline buffer may be swapped or moved individually, we force the creation of out-of-line buffer
+ // so we can make sure there's no element-wise copy/move.
+ Deque<CountCopy, 1> deque;
+ int counter = 0;
+ deque.append(CountCopy(&counter));
+ deque.append(CountCopy(&counter));
+
+ Deque<CountCopy, 1> other(deque);
+ counter = 0;
+ deque = std::move(other); // Move assignment.
+ EXPECT_EQ(0, counter);
+
+ counter = 0;
+ Deque<CountCopy, 1> yetAnother(std::move(deque)); // Move construction.
+ EXPECT_EQ(0, counter);
+}
+
} // anonymous namespace
} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/Deque.h ('k') | third_party/WebKit/Source/wtf/HashMapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698