aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTLazy.h
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-11-28 16:44:10 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-28 22:13:47 +0000
commite819e5f81e76fa88955b19467edc83b7ca6a4ff9 (patch)
tree412ff0b9d53f5dc4a8740f593c8c0bc8e604e43a /include/core/SkTLazy.h
parentb2ab78eac9a383a137a85e1192546c0e775c09de (diff)
Update SkTLazy for move only types.
Change-Id: Id812d4f6ac47ae41e5a938310aa8f30eaf33a42d Reviewed-on: https://skia-review.googlesource.com/76901 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r--include/core/SkTLazy.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index cb08387bb9..39ebdbef4a 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -24,7 +24,8 @@ public:
explicit SkTLazy(const T* src)
: fPtr(src ? new (fStorage.get()) T(*src) : nullptr) {}
- SkTLazy(const SkTLazy& src) : fPtr(nullptr) { *this = src; }
+ SkTLazy(const SkTLazy& that) : fPtr(nullptr) { *this = that; }
+ SkTLazy(SkTLazy&& that) : fPtr(nullptr) { *this = std::move(that); }
~SkTLazy() {
if (this->isValid()) {
@@ -32,9 +33,18 @@ public:
}
}
- SkTLazy& operator=(const SkTLazy& src) {
- if (src.isValid()) {
- this->set(*src.get());
+ SkTLazy& operator=(const SkTLazy& that) {
+ if (that.isValid()) {
+ this->set(*that.get());
+ } else {
+ this->reset();
+ }
+ return *this;
+ }
+
+ SkTLazy& operator=(SkTLazy&& that) {
+ if (that.isValid()) {
+ this->set(std::move(*that.get()));
} else {
this->reset();
}
@@ -70,6 +80,15 @@ public:
return fPtr;
}
+ T* set(T&& src) {
+ if (this->isValid()) {
+ *fPtr = std::move(src);
+ } else {
+ fPtr = new (SkTCast<T*>(fStorage.get())) T(std::move(src));
+ }
+ return fPtr;
+ }
+
/**
* Destroy the lazy object (if it was created via init() or set())
*/