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

Unified Diff: src/core/SkData.cpp

Issue 15675025: One allocation for an SkData which makes a copy. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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/SkWeakRefCnt.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkData.cpp
===================================================================
--- src/core/SkData.cpp (revision 9507)
+++ src/core/SkData.cpp (working copy)
@@ -58,7 +58,7 @@
return gEmptyRef;
}
-// assumes fPtr was allocated via sk_malloc
+/** Assumes ptr was allocated via sk_malloc, ignores the size and context. */
static void sk_free_releaseproc(const void* ptr, size_t, void*) {
sk_free((void*)ptr);
}
@@ -67,14 +67,34 @@
return new SkData(data, length, sk_free_releaseproc, NULL);
}
+/** This is a global marker function which does nothing itself.
+ * When set as the release proc and the ref count goes to zero,
+ * the destructor will be called, followed by sk_free(context).
+ */
+static void sk_free_after_destructor_releaseproc(const void*, size_t, void*) {
+ // This function intentionally left blank.
reed1 2013/06/11 21:28:15 SkASSERT(!"don't call me");
bungeman-skia 2013/06/11 22:25:32 Removed this function.
+}
+
+void SkData::internal_dispose() const {
+ if (sk_free_after_destructor_releaseproc == this->fReleaseProc) {
+ this->internal_dispose_restore_refcnt_to_1();
+ void* context = this->fReleaseProcContext;
reed1 2013/06/11 21:28:15 Isn't context always == this? can we call free on
bungeman-skia 2013/06/11 22:25:32 Hmmmm... yes, we do magically know that. In fact,
+ this->~SkData();
+ sk_free(context);
+ return;
+ }
+ this->INHERITED::internal_dispose();
+}
+
SkData* SkData::NewWithCopy(const void* data, size_t length) {
if (0 == length) {
return SkData::NewEmpty();
}
- void* copy = sk_malloc_throw(length); // balanced in sk_free_releaseproc
+ char* everything = reinterpret_cast<char*>(sk_malloc_throw(sizeof(SkData) + length));
reed1 2013/06/11 21:28:15 This is an 80-col file...
bungeman-skia 2013/06/11 22:25:32 Done.
+ char* copy = everything + sizeof(SkData);
memcpy(copy, data, length);
- return new SkData(copy, length, sk_free_releaseproc, NULL);
+ return SkNEW_PLACEMENT_ARGS(everything, SkData, (copy, length, sk_free_after_destructor_releaseproc, everything));
}
SkData* SkData::NewWithProc(const void* data, size_t length,
« no previous file with comments | « include/core/SkWeakRefCnt.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698