Diff
Modified: trunk/Source/WTF/ChangeLog (180065 => 180066)
--- trunk/Source/WTF/ChangeLog 2015-02-13 19:50:03 UTC (rev 180065)
+++ trunk/Source/WTF/ChangeLog 2015-02-13 19:52:56 UTC (rev 180066)
@@ -1,5 +1,16 @@
2015-02-13 Anders Carlsson <ander...@apple.com>
+ Add a move constructor and move assignment operator to Deque
+ https://bugs.webkit.org/show_bug.cgi?id=141571
+
+ Reviewed by Andreas Kling.
+
+ * wtf/Deque.h:
+ (WTF::inlineCapacity>::Deque):
+ (WTF::=): Deleted.
+
+2015-02-13 Anders Carlsson <ander...@apple.com>
+
Add an initializer list constructor to Deque
https://bugs.webkit.org/show_bug.cgi?id=141565
Modified: trunk/Source/WTF/wtf/Deque.h (180065 => 180066)
--- trunk/Source/WTF/wtf/Deque.h 2015-02-13 19:50:03 UTC (rev 180065)
+++ trunk/Source/WTF/wtf/Deque.h 2015-02-13 19:52:56 UTC (rev 180066)
@@ -53,12 +53,15 @@
Deque();
Deque(std::initializer_list<T>);
- Deque(const Deque<T, inlineCapacity>&);
- Deque& operator=(const Deque<T, inlineCapacity>&);
+ Deque(const Deque&);
+ Deque(Deque&&);
~Deque();
- void swap(Deque<T, inlineCapacity>&);
+ Deque& operator=(const Deque&);
+ Deque& operator=(Deque&&);
+ void swap(Deque&);
+
size_t size() const { return m_start <= m_end ? m_end - m_start : m_end + m_buffer.capacity() - m_start; }
bool isEmpty() const { return m_start == m_end; }
@@ -282,7 +285,7 @@
}
template<typename T, size_t inlineCapacity>
-inline Deque<T, inlineCapacity>::Deque(const Deque<T, inlineCapacity>& other)
+inline Deque<T, inlineCapacity>::Deque(const Deque& other)
: m_start(other.m_start)
, m_end(other.m_end)
, m_buffer(other.m_buffer.capacity())
@@ -300,8 +303,15 @@
}
template<typename T, size_t inlineCapacity>
-inline Deque<T, inlineCapacity>& Deque<T, inlineCapacity>::operator=(const Deque<T, inlineCapacity>& other)
+inline Deque<T, inlineCapacity>::Deque(Deque&& other)
+ : Deque()
{
+ swap(other);
+}
+
+template<typename T, size_t inlineCapacity>
+inline auto Deque<T, inlineCapacity>::operator=(const Deque& other) -> Deque&
+{
// FIXME: This is inefficient if we're using an inline buffer and T is
// expensive to copy since it will copy the buffer twice instead of once.
Deque<T, inlineCapacity> copy(other);
@@ -310,6 +320,13 @@
}
template<typename T, size_t inlineCapacity>
+inline auto Deque<T, inlineCapacity>::operator=(Deque&& other) -> Deque&
+{
+ swap(other);
+ return *this;
+}
+
+template<typename T, size_t inlineCapacity>
inline void Deque<T, inlineCapacity>::destroyAll()
{
if (m_start <= m_end)
Modified: trunk/Tools/ChangeLog (180065 => 180066)
--- trunk/Tools/ChangeLog 2015-02-13 19:50:03 UTC (rev 180065)
+++ trunk/Tools/ChangeLog 2015-02-13 19:52:56 UTC (rev 180066)
@@ -1,3 +1,13 @@
+2015-02-13 Anders Carlsson <ander...@apple.com>
+
+ Add a move constructor and move assignment operator to Deque
+ https://bugs.webkit.org/show_bug.cgi?id=141571
+
+ Reviewed by Andreas Kling.
+
+ * TestWebKitAPI/Tests/WTF/Deque.cpp:
+ (TestWebKitAPI::TEST):
+
2015-02-13 Csaba Osztrogonác <o...@webkit.org>
run-jsc-stress-tests --remote should skip profiler tests
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Deque.cpp (180065 => 180066)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Deque.cpp 2015-02-13 19:50:03 UTC (rev 180065)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Deque.cpp 2015-02-13 19:52:56 UTC (rev 180066)
@@ -144,4 +144,48 @@
EXPECT_EQ(1U, last.value());
}
+TEST(WTF_Deque, MoveConstructor)
+{
+ Deque<MoveOnly, 4> deque;
+
+ for (unsigned i = 0; i < 10; ++i)
+ deque.append(MoveOnly(i));
+
+ EXPECT_EQ(10u, deque.size());
+
+ Deque<MoveOnly, 4> deque2 = WTF::move(deque);
+
+ EXPECT_EQ(10u, deque2.size());
+
+ unsigned i = 0;
+ for (auto& element : deque2) {
+ EXPECT_EQ(i, element.value());
+ ++i;
+ }
+}
+
+TEST(WTF_Deque, MoveAssignmentOperator)
+{
+ Deque<MoveOnly, 4> deque1;
+
+ for (unsigned i = 0; i < 10; ++i)
+ deque1.append(MoveOnly(i));
+
+ EXPECT_EQ(10u, deque1.size());
+
+ Deque<MoveOnly, 4> deque2;
+ for (unsigned i = 0; i < 10; ++i)
+ deque2.append(MoveOnly(i * 2));
+
+ deque1 = WTF::move(deque2);
+
+ EXPECT_EQ(10u, deque2.size());
+
+ unsigned i = 0;
+ for (auto& element : deque1) {
+ EXPECT_EQ(i * 2, element.value());
+ ++i;
+ }
+}
+
} // namespace TestWebKitAPI