Switch SkAutoMalloc to SkAutoTMalloc to avoid cast
Make SkAutoTMalloc's interface look more like SkAutoMalloc:
- add free(), which does what you expect
- make reset() return a pointer fPtr
No public API changes (SkAutoTMalloc is in include/private)
BUG=skia:2148
Review URL: https://codereview.chromium.org/1516833003
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 533cb26..c1fd4cb 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -272,9 +272,10 @@
}
/** Resize the memory area pointed to by the current ptr without preserving contents. */
- void reset(size_t count) {
+ T* reset(size_t count) {
sk_free(fPtr);
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW);
+ return fPtr;
}
T* get() const { return fPtr; }
@@ -296,6 +297,13 @@
}
/**
+ * Releases the block back to the heap
+ */
+ void free() {
+ this->reset(0);
+ }
+
+ /**
* Transfer ownership of the ptr 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.