aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTLazy.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r--include/core/SkTLazy.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index cd1e8f2b9c..315bd95101 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -116,10 +116,21 @@ class SkTCopyOnFirstWrite {
public:
SkTCopyOnFirstWrite(const T& initial) : fObj(&initial) {}
+ // Constructor for delayed initialization.
+ SkTCopyOnFirstWrite() : fObj(NULL) {}
+
+ // Should only be called once, and only if the default constructor was used.
+ void init(const T& initial) {
+ SkASSERT(NULL == fObj);
+ SkASSERT(!fLazy.isValid());
+ fObj = &initial;
+ }
+
/**
* Returns a writable T*. The first time this is called the initial object is cloned.
*/
T* writable() {
+ SkASSERT(NULL != fObj);
if (!fLazy.isValid()) {
fLazy.set(*fObj);
fObj = fLazy.get();