Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: include/private/SkTemplates.h

Issue 1813843002: Revert of free -> reset (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkTypes.h ('k') | src/codec/SkBmpCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkTemplates.h
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 8850a29a63653798d03af5313fb6622bdba34820..526c307558c6a98db262d54ef37bc5548af69f14 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -96,6 +96,7 @@
SkAutoTDelete(T* obj = NULL) : std::unique_ptr<T>(obj) {}
operator T*() const { return this->get(); }
+ void free() { this->reset(nullptr); }
// See SkAutoTUnref for why we do this.
explicit operator bool() const { return this->get() != nullptr; }
@@ -104,6 +105,8 @@
template <typename T> class SkAutoTDeleteArray : public std::unique_ptr<T[]> {
public:
SkAutoTDeleteArray(T array[]) : std::unique_ptr<T[]>(array) {}
+
+ void free() { this->reset(nullptr); }
};
/** Allocate an array of T elements, and free the array in the destructor
@@ -278,9 +281,9 @@
}
/** Resize the memory area pointed to by the current ptr without preserving contents. */
- T* reset(size_t count = 0) {
+ T* reset(size_t count) {
sk_free(fPtr);
- fPtr = count ? (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW) : nullptr;
+ fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW);
return fPtr;
}
@@ -300,6 +303,13 @@
const T& operator[](int index) const {
return fPtr[index];
+ }
+
+ /**
+ * Releases the block back to the heap
+ */
+ void free() {
+ this->reset(0);
}
/**
« no previous file with comments | « include/core/SkTypes.h ('k') | src/codec/SkBmpCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698