diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-18 18:43:26 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-18 18:43:26 +0000 |
commit | 9d1cff124c14e550889a5755ffa5e6537af7c8c8 (patch) | |
tree | 6dacc454a758e8b9c4e8b2b3f5b8062062ebae06 | |
parent | 9584b9ebd84993afc89b503217cc1012c70ed559 (diff) |
use SkAutoTDelete instead of SkTScopedPtr
Review URL: https://codereview.chromium.org/13831011
git-svn-id: http://skia.googlecode.com/svn/trunk@8749 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/GrMemoryPoolBench.cpp | 6 | ||||
-rw-r--r-- | include/core/SkTemplates.h | 10 | ||||
-rw-r--r-- | tests/GrMemoryPoolTest.cpp | 6 |
3 files changed, 14 insertions, 8 deletions
diff --git a/bench/GrMemoryPoolBench.cpp b/bench/GrMemoryPoolBench.cpp index 29c0893f92..dccf8278f5 100644 --- a/bench/GrMemoryPoolBench.cpp +++ b/bench/GrMemoryPoolBench.cpp @@ -11,8 +11,8 @@ #include "GrMemoryPool.h" #include "SkBenchmark.h" #include "SkRandom.h" -#include "SkTScopedPtr.h" #include "SkTDArray.h" +#include "SkTemplates.h" // change this to 0 to compare GrMemoryPool to default new / delete #define OVERRIDE_NEW 1 @@ -107,14 +107,14 @@ protected: enum { kMaxObjects = 4 * (1 << 10), }; - SkTScopedPtr<A> objects[kMaxObjects]; + SkAutoTDelete<A> objects[kMaxObjects]; for (int i = 0; i < N; i++) { uint32_t idx = r.nextRangeU(0, kMaxObjects-1); if (NULL == objects[idx].get()) { objects[idx].reset(new A); } else { - objects[idx].reset(NULL); + objects[idx].free(); } } } diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h index c4ba0e676a..9078bd2036 100644 --- a/include/core/SkTemplates.h +++ b/include/core/SkTemplates.h @@ -80,16 +80,22 @@ private: T* fObj; }; -// See also SkTScopedPtr. template <typename T> class SkAutoTDelete : SkNoncopyable { public: - SkAutoTDelete(T* obj) : fObj(obj) {} + SkAutoTDelete(T* obj = NULL) : fObj(obj) {} ~SkAutoTDelete() { delete fObj; } T* get() const { return fObj; } T& operator*() const { SkASSERT(fObj); return *fObj; } T* operator->() const { SkASSERT(fObj); return fObj; } + void reset(T* obj) { + if (fObj != obj) { + delete fObj; + fObj = obj; + } + } + /** * Delete the owned object, setting the internal pointer to NULL. */ diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp index 73f26a9b2e..0ed77bf5b1 100644 --- a/tests/GrMemoryPoolTest.cpp +++ b/tests/GrMemoryPoolTest.cpp @@ -11,7 +11,7 @@ #include "GrMemoryPool.h" #include "SkRandom.h" #include "SkTDArray.h" -#include "SkTScopedPtr.h" +#include "SkTemplates.h" #include "SkInstCnt.h" namespace { @@ -65,11 +65,11 @@ public: } private: - static SkTScopedPtr<GrMemoryPool> gPool; + static SkAutoTDelete<GrMemoryPool> gPool; char fChar; }; SK_DEFINE_INST_COUNT(A); -SkTScopedPtr<GrMemoryPool> A::gPool; +SkAutoTDelete<GrMemoryPool> A::gPool; class B : public A { public: |