Chromium Code Reviews| 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; |