Chromium Code Reviews| Index: include/core/SkTLazy.h |
| diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h |
| index 399b26cde84d071427d7bdee6a1dfbede6a4b10f..30969c8b43411f39c4b651012b65b7cd07197d18 100644 |
| --- a/include/core/SkTLazy.h |
| +++ b/include/core/SkTLazy.h |
| @@ -19,21 +19,13 @@ |
| */ |
| 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<T>& src) |
|
mtklein
2016/08/10 18:59:46
It can be reassuring to see the copy constructor i
f(malita)
2016/08/10 20:01:01
Done.
This does add a couple of redundant isValid
|
| + : fPtr(src.isValid() ? new (fStorage.get()) T(*src.get()) : nullptr) {} |
| ~SkTLazy() { |
| if (this->isValid()) { |
| @@ -41,6 +33,15 @@ public: |
| } |
| } |
| + SkTLazy& operator=(const SkTLazy<T>& src) { |
|
mtklein
2016/08/10 18:59:46
I think there's no need for the <T> in these argum
f(malita)
2016/08/10 20:01:01
Done.
|
| + 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 +77,7 @@ public: |
| void reset() { |
| if (this->isValid()) { |
| fPtr->~T(); |
| - fPtr = NULL; |
| + fPtr = nullptr; |
| } |
| } |
| @@ -94,12 +95,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 +135,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; |
| } |