| Index: include/core/SkTLazy.h
|
| diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
|
| index 399b26cde84d071427d7bdee6a1dfbede6a4b10f..31dce6085f96779c3137fc5bf4011766a91b31f4 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;
|
| }
|
|
|