Stop overloading internal_dispose in SkTextBlob and SkData
Review URL: https://codereview.chromium.org/737093002
diff --git a/include/core/SkData.h b/include/core/SkData.h
index 4f0c213..0e4a474 100644
--- a/include/core/SkData.h
+++ b/include/core/SkData.h
@@ -168,7 +168,14 @@
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();
diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h
index 8ee1d19..334cfb9 100644
--- a/include/core/SkTextBlob.h
+++ b/include/core/SkTextBlob.h
@@ -79,7 +79,15 @@
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);
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index c5d1077..dfbd003 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -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(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 @@
}
}
-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;
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index f298b54..0b81cb6 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -122,13 +122,6 @@
}
}
-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;