Flutter Engine
The Flutter Engine
|
#include <SkTLazy.h>
Public Member Functions | |
SkTCopyOnFirstWrite (const T &initial) | |
SkTCopyOnFirstWrite (const T *initial) | |
SkTCopyOnFirstWrite () | |
SkTCopyOnFirstWrite (const SkTCopyOnFirstWrite &that) | |
SkTCopyOnFirstWrite (SkTCopyOnFirstWrite &&that) | |
SkTCopyOnFirstWrite & | operator= (const SkTCopyOnFirstWrite &that) |
SkTCopyOnFirstWrite & | operator= (SkTCopyOnFirstWrite &&that) |
void | init (const T &initial) |
template<typename... Args> | |
void | initIfNeeded (Args &&... args) |
T * | writable () |
const T * | get () const |
const T * | operator-> () const |
operator const T * () const | |
const T & | operator* () const |
A helper built on top of std::optional to do copy-on-first-write. The object is initialized with a const pointer but provides a non-const pointer accessor. The first time the accessor is called (if ever) the object is cloned.
In the following example at most one copy of constThing is made:
SkTCopyOnFirstWrite<Thing> thing(&constThing); ... function_that_takes_a_const_thing_ptr(thing); // constThing is passed ... if (need_to_modify_thing()) { thing.writable()->modifyMe(); // makes a copy of constThing } ... x = thing->readSomething(); ... if (need_to_modify_thing_now()) { thing.writable()->changeMe(); // makes a copy of constThing if we didn't call modifyMe() }
consume_a_thing(thing); // could be constThing or a modified copy.
|
inlineexplicit |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |