Stop overloading internal_dispose in SkTextBlob and SkData

Review URL: https://codereview.chromium.org/737093002
This commit is contained in:
bsalomon 2014-11-20 08:02:46 -08:00 committed by Commit bot
parent 7cc1a34fbf
commit 072803144a
4 changed files with 18 additions and 29 deletions

View File

@ -168,7 +168,14 @@ private:
SkData(size_t size); // inplace new/delete
virtual ~SkData();
virtual void internal_dispose() const SK_OVERRIDE;
// Objects of this type are sometimes created in a custom fashion using sk_malloc_throw and
// therefore must be sk_freed. We overload new to also call sk_malloc_throw so that memory
// can be unconditionally released using sk_free in an overloaded delete. Overloading regular
// new means we must also overload placement new.
void* operator new(size_t size) { return sk_malloc_throw(size); }
void* operator new(size_t, void* p) { return p; }
void operator delete(void* p) { sk_free(p); }
// Called the first time someone calls NewEmpty to initialize the singleton.
friend SkData* sk_new_empty_data();

View File

@ -79,7 +79,15 @@ private:
SkTextBlob(int runCount, const SkRect& bounds);
virtual ~SkTextBlob();
virtual void internal_dispose() const SK_OVERRIDE;
// Memory for objects of this class is created with sk_malloc rather than operator new and must
// be freed with sk_free.
void operator delete(void* p) { sk_free(p); }
void* operator new(size_t) {
SkFAIL("All blobs are created by placement new.");
return sk_malloc_throw(0);
}
void* operator new(size_t, void* p) { return p; }
static unsigned ScalarsPerGlyph(GlyphPositioning pos);

View File

@ -12,11 +12,6 @@
#include "SkStream.h"
#include "SkWriteBuffer.h"
static void sk_inplace_sentinel_releaseproc(const void*, size_t, void*) {
// we should never get called, as we are just a sentinel
sk_throw();
}
SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
fPtr = const_cast<void*>(ptr);
fSize = size;
@ -31,7 +26,7 @@ SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
SkData::SkData(size_t size) {
fPtr = (char*)(this + 1); // contents are immediately after this
fSize = size;
fReleaseProc = sk_inplace_sentinel_releaseproc;
fReleaseProc = NULL;
fReleaseProcContext = NULL;
}
@ -41,20 +36,6 @@ SkData::~SkData() {
}
}
void SkData::internal_dispose() const {
if (sk_inplace_sentinel_releaseproc == fReleaseProc) {
const_cast<SkData*>(this)->fReleaseProc = NULL; // so we don't call it in our destructor
this->internal_dispose_restore_refcnt_to_1();
this->~SkData(); // explicitly call this for refcnt bookkeeping
sk_free(const_cast<SkData*>(this));
} else {
this->internal_dispose_restore_refcnt_to_1();
SkDELETE(this);
}
}
bool SkData::equals(const SkData* other) const {
if (NULL == other) {
return false;

View File

@ -122,13 +122,6 @@ SkTextBlob::~SkTextBlob() {
}
}
void SkTextBlob::internal_dispose() const {
// SkTextBlobs use externally-managed storage.
this->internal_dispose_restore_refcnt_to_1();
this->~SkTextBlob();
sk_free(const_cast<SkTextBlob*>(this));
}
uint32_t SkTextBlob::uniqueID() const {
static int32_t gTextBlobGenerationID; // = 0;