diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-09-20 18:04:12 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-09-20 18:04:12 +0000 |
commit | 52657c75b5d4c0e72d64ecaec504b26d0d215a33 (patch) | |
tree | 7271bcf99bd1242aa7e41f307f522bf8bbb18fff /include | |
parent | cc9471c36d3967270f7eb26f8b53ce0f17bc9fbb (diff) |
remove unused parameter (that also slowed us down) to SkAutoTDelete
git-svn-id: http://skia.googlecode.com/svn/trunk@5611 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkTemplates.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h index 3570946316..b7831ea961 100644 --- a/include/core/SkTemplates.h +++ b/include/core/SkTemplates.h @@ -76,18 +76,34 @@ private: // See also SkTScopedPtr. template <typename T> class SkAutoTDelete : SkNoncopyable { public: - SkAutoTDelete(T* obj, bool deleteWhenDone = true) : fObj(obj) { - fDeleteWhenDone = deleteWhenDone; + SkAutoTDelete(T* obj) : fObj(obj) {} + ~SkAutoTDelete() { delete fObj; } + + T* get() const { return fObj; } + T& operator*() const { SkASSERT(fObj); return *fObj; } + T* operator->() const { SkASSERT(fObj); return fObj; } + + /** + * Delete the owned object, setting the internal pointer to NULL. + */ + void free() { + delete fObj; + fObj = NULL; } - ~SkAutoTDelete() { if (fDeleteWhenDone) delete fObj; } - T* get() const { return fObj; } - void free() { delete fObj; fObj = NULL; } - T* detach() { T* obj = fObj; fObj = NULL; return obj; } + /** + * Transfer ownership of the object to the caller, setting the internal + * pointer to NULL. Note that this differs from get(), which also returns + * the pointer, but it does not transfer ownership. + */ + T* detach() { + T* obj = fObj; + fObj = NULL; + return obj; + } private: T* fObj; - bool fDeleteWhenDone; }; template <typename T> class SkAutoTDeleteArray : SkNoncopyable { |