diff options
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r-- | include/core/SkTLazy.h | 27 |
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()) */ |