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>
This commit is contained in:
Ben Wagner 2017-11-28 16:44:10 -05:00 committed by Skia Commit-Bot
parent b2ab78eac9
commit e819e5f81e

View File

@ -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())
*/