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 | |
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
-rw-r--r-- | include/private/SkTDArray.h | 19 | ||||
-rw-r--r-- | src/core/SkAdvancedTypefaceMetrics.h | 15 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.h | 18 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.cpp | 9 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.h | 4 | ||||
-rw-r--r-- | src/utils/SkMultiPictureDocument.cpp | 8 |
6 files changed, 22 insertions, 51 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 && diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h index 026aec26f4..6dc1162c37 100644 --- a/src/core/SkAdvancedTypefaceMetrics.h +++ b/src/core/SkAdvancedTypefaceMetrics.h @@ -120,19 +120,8 @@ public: uint16_t fEndId; SkTDArray<Data> fAdvance; AdvanceMetric(uint16_t startId) : fStartId(startId) {} - AdvanceMetric(AdvanceMetric&& other) - : fType(other.fType) - , fStartId(other.fStartId) - , fEndId(other.fEndId) { - fAdvance.swap(other.fAdvance); - } - AdvanceMetric& operator=(AdvanceMetric&& other) { - fType = other.fType; - fStartId = other.fStartId; - fEndId = other.fEndId; - fAdvance.swap(other.fAdvance); - return *this; - } + AdvanceMetric(AdvanceMetric&& other) = default; + AdvanceMetric& operator=(AdvanceMetric&& other) = default; AdvanceMetric(const AdvanceMetric&) = delete; AdvanceMetric& operator=(const AdvanceMetric&) = delete; }; diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index 5fedd0eb4c..74047521c5 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -206,13 +206,8 @@ private: sk_sp<SkData> data; RectWithData(const SkRect& rect, SkData* data) : rect(rect), data(SkRef(data)) {} - RectWithData(RectWithData&& other) - : rect(other.rect), data(std::move(other.data)) {} - RectWithData& operator=(RectWithData&& other) { - rect = other.rect; - data = std::move(other.data); - return *this; - } + RectWithData(RectWithData&&) = default; + RectWithData& operator=(RectWithData&& other) = default; }; struct NamedDestination { @@ -220,13 +215,8 @@ private: SkPoint point; NamedDestination(SkData* nameData, const SkPoint& point) : nameData(SkRef(nameData)), point(point) {} - NamedDestination(NamedDestination&& other) - : nameData(std::move(other.nameData)), point(other.point) {} - NamedDestination& operator=(NamedDestination&& other) { - nameData = std::move(other.nameData); - point = other.point; - return *this; - } + NamedDestination(NamedDestination&&) = default; + NamedDestination& operator=(NamedDestination&&) = default; }; // TODO(vandebo): push most of SkPDFDevice's state into a core object in diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index f16e56f436..afb9b72c54 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -397,15 +397,6 @@ void SkPDFDict::addResources(SkPDFObjNumMap* catalog, SkPDFDict::Record::Record(SkPDFUnion&& k, SkPDFUnion&& v) : fKey(std::move(k)), fValue(std::move(v)) {} -SkPDFDict::Record::Record(SkPDFDict::Record&& o) - : fKey(std::move(o.fKey)), fValue(std::move(o.fValue)) {} - -SkPDFDict::Record& SkPDFDict::Record::operator=(SkPDFDict::Record&& o) { - fKey = std::move(o.fKey); - fValue = std::move(o.fValue); - return *this; -} - int SkPDFDict::size() const { return fRecords.count(); } void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) { diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 52ce221725..cdfef6cb92 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -290,8 +290,8 @@ private: SkPDFUnion fKey; SkPDFUnion fValue; Record(SkPDFUnion&&, SkPDFUnion&&); - Record(Record&&); - Record& operator=(Record&&); + Record(Record&&) = default; + Record& operator=(Record&&) = default; Record(const Record&) = delete; Record& operator=(const Record&) = delete; }; diff --git a/src/utils/SkMultiPictureDocument.cpp b/src/utils/SkMultiPictureDocument.cpp index e4105fa31d..214e6ad537 100644 --- a/src/utils/SkMultiPictureDocument.cpp +++ b/src/utils/SkMultiPictureDocument.cpp @@ -60,14 +60,10 @@ struct NullWStream : public SkWStream { struct Page { Page(SkSize s, sk_sp<SkPicture> c) : fSize(s), fContent(std::move(c)) {} - Page(Page&& that) : fSize(that.fSize), fContent(std::move(that.fContent)) {} + Page(Page&&) = default; Page(const Page&) = default; Page& operator=(const Page&) = default; - Page& operator=(Page&& that) { - fSize = that.fSize; - fContent = std::move(that.fContent); - return *this; - } + Page& operator=(Page&&) = default; SkSize fSize; sk_sp<SkPicture> fContent; }; |