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

Unified Diff: src/core/SkSmallAllocator.h

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up Created 6 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
Index: src/core/SkSmallAllocator.h
diff --git a/src/core/SkSmallAllocator.h b/src/core/SkSmallAllocator.h
index 2eddb510cd050ed6cce16915fab0560c847f0404..e9fe9b78ff7396255f11ba8bd2d81ba141c7151c 100644
--- a/src/core/SkSmallAllocator.h
+++ b/src/core/SkSmallAllocator.h
@@ -42,7 +42,9 @@ public:
while (fNumObjects > 0) {
fNumObjects--;
Rec* rec = &fRecs[fNumObjects];
- rec->fKillProc(rec->fObj);
+ if (rec->fObj) {
+ rec->fKillProc(rec->fObj);
+ }
// Safe to do if fObj is in fStorage, since fHeapStorage will
// point to NULL.
sk_free(rec->fHeapStorage);
@@ -131,6 +133,25 @@ public:
return rec->fObj;
}
+ /*
+ * Free the memory reserved for an object without calling its destructor.
+ * Assumes the passed-in pointer has previously been returned by either
+ * createT or reserveT.
+ */
+ void free(void* obj) {
+ // Find the corresponding Rec.
scroggo 2014/03/24 21:24:46 Do we think it's necessary to allow freeing anythi
Dominik Grewe 2014/03/26 17:22:22 Sounds good to me. I've implemented it. If we also
scroggo 2014/03/26 23:13:09 That seems reasonable. It might be nice to know ho
Dominik Grewe 2014/03/27 14:27:20 During the tests (excluding the ones using gradien
+ Rec* rec = NULL;
+ for (uint32_t i = 0; i < fNumObjects; i++) {
+ if (fRecs[i].fObj == obj) {
+ rec = &fRecs[i];
+ break;
+ }
+ }
+ SkASSERT(rec);
+ // The rest of the cleanup will be done in the destructor.
+ rec->fObj = NULL;
+ }
+
private:
struct Rec {
void* fObj;

Powered by Google App Engine
This is Rietveld 408576698