Add SkSTArray move assignment operators
authorFlorin Malita <fmalita@chromium.org>
Sun, 12 Mar 2017 14:40:13 +0000 (10:40 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Sun, 12 Mar 2017 15:15:14 +0000 (15:15 +0000)
Change-Id: Ib655a8a4d62c27dee4f92fcb644237f6fbbdb75b
Reviewed-on: https://skia-review.googlesource.com/9510
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Ben Wagner <bungeman@google.com>
include/private/SkTArray.h
tests/TArrayTest.cpp

index 22f6d44cea8ead17bc24c22fbc5cbef4c9a9d0dd..b90b41d7c54aa04718bacd564f4a36065d187244 100644 (file)
@@ -569,7 +569,13 @@ public:
     }
 
     SkSTArray& operator= (const SkSTArray& array) {
-        return *this = *(const INHERITED*)&array;
+        INHERITED::operator=(array);
+        return *this;
+    }
+
+    SkSTArray& operator= (SkSTArray&& array) {
+        INHERITED::operator=(std::move(array));
+        return *this;
     }
 
     SkSTArray& operator= (const INHERITED& array) {
@@ -577,6 +583,11 @@ public:
         return *this;
     }
 
+    SkSTArray& operator= (INHERITED&& array) {
+        INHERITED::operator=(std::move(array));
+        return *this;
+    }
+
 private:
     SkAlignedSTStorage<N,T> fStorage;
 };
index ee6aabc63a42f414fde5e7adf37da30a39052b14..d1331b58a8b55790af34f931f7036d60fcdae7ae 100644 (file)
@@ -138,6 +138,87 @@ void test_copy_ctor(skiatest::Reporter* reporter, SkTArray<T, MEM_MOVE>&& array)
         REPORTER_ASSERT(reporter, ref->unique());
 }
 
+static void test_move(skiatest::Reporter* reporter) {
+#define TEST_MOVE do {                                 \
+    SRC_T src;                                         \
+    src.emplace_back(sk_make_sp<SkRefCnt>());          \
+    {                                                  \
+        /* copy ctor */                                \
+        DST_T copy(src);                               \
+        REPORTER_ASSERT(reporter, !copy[0]->unique()); \
+    }                                                  \
+    {                                                  \
+        /* move ctor */                                \
+        DST_T move(std::move(src));                    \
+        REPORTER_ASSERT(reporter, move[0]->unique());  \
+    }                                                  \
+    REPORTER_ASSERT(reporter, src.empty());            \
+    src.emplace_back(sk_make_sp<SkRefCnt>());          \
+    {                                                  \
+        /* copy assignment */                          \
+        DST_T copy;                                    \
+        copy = src;                                    \
+        REPORTER_ASSERT(reporter, !copy[0]->unique()); \
+    }                                                  \
+    {                                                  \
+        /* move assignment */                          \
+        DST_T move;                                    \
+        move = std::move(src);                         \
+        REPORTER_ASSERT(reporter, move[0]->unique());  \
+    }                                                  \
+    REPORTER_ASSERT(reporter, src.empty());            \
+} while (false)
+
+    {
+        using SRC_T = SkTArray<sk_sp<SkRefCnt>, false>;
+        using DST_T = SkTArray<sk_sp<SkRefCnt>, false>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkTArray<sk_sp<SkRefCnt>, true>;
+        using DST_T = SkTArray<sk_sp<SkRefCnt>, true>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkSTArray<1, sk_sp<SkRefCnt>, false>;
+        using DST_T = SkSTArray<1, sk_sp<SkRefCnt>, false>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkSTArray<1, sk_sp<SkRefCnt>, true>;
+        using DST_T = SkSTArray<1, sk_sp<SkRefCnt>, true>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkTArray<sk_sp<SkRefCnt>, false>;
+        using DST_T = SkSTArray<1, sk_sp<SkRefCnt>, false>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkTArray<sk_sp<SkRefCnt>, true>;
+        using DST_T = SkSTArray<1, sk_sp<SkRefCnt>, true>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkSTArray<1, sk_sp<SkRefCnt>, false>;
+        using DST_T = SkTArray<sk_sp<SkRefCnt>, false>;
+        TEST_MOVE;
+    }
+
+    {
+        using SRC_T = SkSTArray<1, sk_sp<SkRefCnt>, true>;
+        using DST_T = SkTArray<sk_sp<SkRefCnt>, true>;
+        TEST_MOVE;
+    }
+#undef TEST_MOVE
+}
+
 DEF_TEST(TArray, reporter) {
     TestTSet_basic<true>(reporter);
     TestTSet_basic<false>(reporter);
@@ -149,4 +230,6 @@ DEF_TEST(TArray, reporter) {
     test_copy_ctor(reporter, SkSTArray< 1, sk_sp<SkRefCnt>,  true>());
     test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>, false>());
     test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>,  true>());
+
+    test_move(reporter);
 }