#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
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();
}
}
}
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.
*/
#include "GrMemoryPool.h"
#include "SkRandom.h"
#include "SkTDArray.h"
-#include "SkTScopedPtr.h"
+#include "SkTemplates.h"
#include "SkInstCnt.h"
namespace {
}
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: