diff options
author | bungeman <bungeman@google.com> | 2016-10-18 08:03:42 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-10-19 15:56:28 +0000 |
commit | 520ced63cf0750e207223169a31edb2a16e5ca96 (patch) | |
tree | 1f0d0132c7c387af42e11e10800d501d4c0ea64b /src/core/SkDescriptor.h | |
parent | 620ee4f744cefbf2fef60add803816398522baae (diff) |
SkDescriptors to be held in unique_ptr.
This also removes the class operator new override along with
directly calling malloc in SkData, since it has a similar requirements.
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot;master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-MSAN-Trybot
Change-Id: Ic68aacf2028d6964d9735a55558862afc9edd19b
Reviewed-on: https://skia-review.googlesource.com/3541
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/core/SkDescriptor.h')
-rw-r--r-- | src/core/SkDescriptor.h | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/core/SkDescriptor.h b/src/core/SkDescriptor.h index efa02783be..0f859137b0 100644 --- a/src/core/SkDescriptor.h +++ b/src/core/SkDescriptor.h @@ -11,6 +11,7 @@ #include "SkOpts.h" #include "SkTypes.h" +#include <memory> class SkDescriptor : SkNoncopyable { public: @@ -19,14 +20,9 @@ public: return sizeof(SkDescriptor) + entryCount * sizeof(Entry); } - static SkDescriptor* Alloc(size_t length) { + static std::unique_ptr<SkDescriptor> Alloc(size_t length) { SkASSERT(SkAlign4(length) == length); - SkDescriptor* desc = (SkDescriptor*)sk_malloc_throw(length); - return desc; - } - - static void Free(SkDescriptor* desc) { - sk_free(desc); + return std::unique_ptr<SkDescriptor>(static_cast<SkDescriptor*>(::operator new (length))); } void init() { @@ -79,9 +75,9 @@ public: return nullptr; } - SkDescriptor* copy() const { - SkDescriptor* desc = SkDescriptor::Alloc(fLength); - memcpy(desc, this, fLength); + std::unique_ptr<SkDescriptor> copy() const { + std::unique_ptr<SkDescriptor> desc = SkDescriptor::Alloc(fLength); + memcpy(desc.get(), this, fLength); return desc; } @@ -149,7 +145,7 @@ public: if (size <= sizeof(fStorage)) { fDesc = (SkDescriptor*)(void*)fStorage; } else { - fDesc = SkDescriptor::Alloc(size); + fDesc = SkDescriptor::Alloc(size).release(); } } @@ -157,7 +153,7 @@ public: private: void free() { if (fDesc != (SkDescriptor*)(void*)fStorage) { - SkDescriptor::Free(fDesc); + delete fDesc; } } |