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) explicit SkTLazy(const T* src)
: fPtr(src ? new (fStorage.get()) T(*src) : nullptr) {} : 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() { ~SkTLazy() {
if (this->isValid()) { if (this->isValid()) {
@ -32,9 +33,18 @@ public:
} }
} }
SkTLazy& operator=(const SkTLazy& src) { SkTLazy& operator=(const SkTLazy& that) {
if (src.isValid()) { if (that.isValid()) {
this->set(*src.get()); this->set(*that.get());
} else {
this->reset();
}
return *this;
}
SkTLazy& operator=(SkTLazy&& that) {
if (that.isValid()) {
this->set(std::move(*that.get()));
} else { } else {
this->reset(); this->reset();
} }
@ -70,6 +80,15 @@ public:
return fPtr; 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()) * Destroy the lazy object (if it was created via init() or set())
*/ */