aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTLazy.h
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-08-10 16:30:37 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-10 16:30:37 -0700
commit0cbe77c383a1c829341b27df1a9219bc33524440 (patch)
tree6c85a5401bd6b67521f9a3821ec03196cec42f48 /include/core/SkTLazy.h
parentac243914af957a806d842318a43dddaf5f941dc3 (diff)
Add a SkTLazy copy assignment operator
Also scrub for NULL, etc. R=mtklein@google.com,reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2232913003 Review-Url: https://codereview.chromium.org/2232913003
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r--include/core/SkTLazy.h36
1 files changed, 18 insertions, 18 deletions
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index 399b26cde8..31dce6085f 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -19,21 +19,12 @@
*/
template <typename T> class SkTLazy {
public:
- SkTLazy() : fPtr(NULL) {}
+ SkTLazy() : fPtr(nullptr) {}
- explicit SkTLazy(const T* src) : fPtr(NULL) {
- if (src) {
- fPtr = new (fStorage.get()) T(*src);
- }
- }
+ explicit SkTLazy(const T* src)
+ : fPtr(src ? new (fStorage.get()) T(*src) : nullptr) {}
- SkTLazy(const SkTLazy<T>& src) : fPtr(NULL) {
- if (src.isValid()) {
- fPtr = new (fStorage.get()) T(*src.get());
- } else {
- fPtr = NULL;
- }
- }
+ SkTLazy(const SkTLazy& src) : fPtr(nullptr) { *this = src; }
~SkTLazy() {
if (this->isValid()) {
@@ -41,6 +32,15 @@ public:
}
}
+ SkTLazy& operator=(const SkTLazy& src) {
+ if (src.isValid()) {
+ this->set(*src.get());
+ } else {
+ this->reset();
+ }
+ return *this;
+ }
+
/**
* Return a pointer to an instance of the class initialized with 'args'.
* If a previous instance had been initialized (either from init() or
@@ -76,7 +76,7 @@ public:
void reset() {
if (this->isValid()) {
fPtr->~T();
- fPtr = NULL;
+ fPtr = nullptr;
}
}
@@ -94,12 +94,12 @@ public:
/**
* Like above but doesn't assert if object isn't initialized (in which case
- * NULL is returned).
+ * nullptr is returned).
*/
T* getMaybeNull() const { return fPtr; }
private:
- T* fPtr; // NULL or fStorage
+ T* fPtr; // nullptr or fStorage
SkAlignedSTStorage<1, T> fStorage;
};
@@ -134,11 +134,11 @@ public:
SkTCopyOnFirstWrite(const T* initial) : fObj(initial) {}
// Constructor for delayed initialization.
- SkTCopyOnFirstWrite() : fObj(NULL) {}
+ SkTCopyOnFirstWrite() : fObj(nullptr) {}
// Should only be called once, and only if the default constructor was used.
void init(const T& initial) {
- SkASSERT(NULL == fObj);
+ SkASSERT(nullptr == fObj);
SkASSERT(!fLazy.isValid());
fObj = &initial;
}