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
diff --git a/include/private/SkTDArray.h b/include/private/SkTDArray.h
index 8af54bb..d6ef3a3 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 @@
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 @@
}
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 &&