diff options
author | halcanary <halcanary@google.com> | 2016-08-08 07:21:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-08 07:21:42 -0700 |
commit | 9be372041ec331f1b04c99890f92d24c59bf9dad (patch) | |
tree | 6b60c1fb924483f633b59dfbc4b7673bafc803e4 /include/private/SkTDArray.h | |
parent | 5d2befe0062c7c8dfc8760d3b3c02846988e9a4e (diff) |
std::move(SkTDArray)
Since we don't support MSVC2013 anymore, we can be more
succinct when defining move constructors of compound types.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2227673002
Review-Url: https://codereview.chromium.org/2227673002
Diffstat (limited to 'include/private/SkTDArray.h')
-rw-r--r-- | include/private/SkTDArray.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/include/private/SkTDArray.h b/include/private/SkTDArray.h index 8af54bbcc5..d6ef3a3834 100644 --- a/include/private/SkTDArray.h +++ b/include/private/SkTDArray.h @@ -14,10 +14,7 @@ template <typename T> class SkTDArray { public: - SkTDArray() { - fReserve = fCount = 0; - fArray = NULL; - } + SkTDArray() : fArray(nullptr), fReserve(0), fCount(0) {} SkTDArray(const T src[], int count) { SkASSERT(src || count == 0); @@ -29,12 +26,13 @@ public: fReserve = fCount = count; } } - SkTDArray(const SkTDArray<T>& src) { - fReserve = fCount = 0; - fArray = NULL; + SkTDArray(const SkTDArray<T>& src) : fArray(nullptr), fReserve(0), fCount(0) { SkTDArray<T> tmp(src.fArray, src.fCount); this->swap(tmp); } + SkTDArray(SkTDArray<T>&& src) : fArray(nullptr), fReserve(0), fCount(0) { + this->swap(src); + } ~SkTDArray() { sk_free(fArray); } @@ -51,6 +49,13 @@ public: } return *this; } + SkTDArray<T>& operator=(SkTDArray<T>&& src) { + if (this != &src) { + this->swap(src); + src.reset(); + } + return *this; + } friend bool operator==(const SkTDArray<T>& a, const SkTDArray<T>& b) { return a.fCount == b.fCount && |