Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: include/core/SkTLazy.h

Issue 2232913003: Add a SkTLazy copy assignment operator (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698