| Index: src/core/SkDataTable.cpp
|
| diff --git a/src/core/SkDataTable.cpp b/src/core/SkDataTable.cpp
|
| index 32e30af64df6dd12dc0fa60e2730676877d8702c..ea2b91b90323d0958b6a8ce047451351ffdd4ef5 100644
|
| --- a/src/core/SkDataTable.cpp
|
| +++ b/src/core/SkDataTable.cpp
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "SkData.h"
|
| #include "SkDataTable.h"
|
| +#include "SkOnce.h"
|
|
|
| static void malloc_freeproc(void* context) {
|
| sk_free(context);
|
| @@ -76,19 +77,17 @@ const void* SkDataTable::at(int index, size_t* size) const {
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| -SkDataTable* SkDataTable::NewEmpty() {
|
| - static SkDataTable* gEmpty;
|
| - if (nullptr == gEmpty) {
|
| - gEmpty = new SkDataTable;
|
| - }
|
| - gEmpty->ref();
|
| - return gEmpty;
|
| +sk_sp<SkDataTable> SkDataTable::MakeEmpty() {
|
| + static SkDataTable* singleton;
|
| + static SkOnce once;
|
| + once([]{ singleton = new SkDataTable(); });
|
| + return sk_ref_sp(singleton);
|
| }
|
|
|
| -SkDataTable* SkDataTable::NewCopyArrays(const void * const * ptrs,
|
| - const size_t sizes[], int count) {
|
| +sk_sp<SkDataTable> SkDataTable::MakeCopyArrays(const void * const * ptrs,
|
| + const size_t sizes[], int count) {
|
| if (count <= 0) {
|
| - return SkDataTable::NewEmpty();
|
| + return SkDataTable::MakeEmpty();
|
| }
|
|
|
| size_t dataSize = 0;
|
| @@ -108,28 +107,27 @@ SkDataTable* SkDataTable::NewCopyArrays(const void * const * ptrs,
|
| elem += sizes[i];
|
| }
|
|
|
| - return new SkDataTable(dir, count, malloc_freeproc, buffer);
|
| + return sk_sp<SkDataTable>(new SkDataTable(dir, count, malloc_freeproc, buffer));
|
| }
|
|
|
| -SkDataTable* SkDataTable::NewCopyArray(const void* array, size_t elemSize,
|
| - int count) {
|
| +sk_sp<SkDataTable> SkDataTable::MakeCopyArray(const void* array, size_t elemSize, int count) {
|
| if (count <= 0) {
|
| - return SkDataTable::NewEmpty();
|
| + return SkDataTable::MakeEmpty();
|
| }
|
|
|
| size_t bufferSize = elemSize * count;
|
| void* buffer = sk_malloc_throw(bufferSize);
|
| memcpy(buffer, array, bufferSize);
|
|
|
| - return new SkDataTable(buffer, elemSize, count, malloc_freeproc, buffer);
|
| + return sk_sp<SkDataTable>(new SkDataTable(buffer, elemSize, count, malloc_freeproc, buffer));
|
| }
|
|
|
| -SkDataTable* SkDataTable::NewArrayProc(const void* array, size_t elemSize,
|
| - int count, FreeProc proc, void* ctx) {
|
| +sk_sp<SkDataTable> SkDataTable::MakeArrayProc(const void* array, size_t elemSize, int count,
|
| + FreeProc proc, void* ctx) {
|
| if (count <= 0) {
|
| - return SkDataTable::NewEmpty();
|
| + return SkDataTable::MakeEmpty();
|
| }
|
| - return new SkDataTable(array, elemSize, count, proc, ctx);
|
| + return sk_sp<SkDataTable>(new SkDataTable(array, elemSize, count, proc, ctx));
|
| }
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
| @@ -164,18 +162,18 @@ void SkDataTableBuilder::append(const void* src, size_t size) {
|
| dir->fSize = size;
|
| }
|
|
|
| -SkDataTable* SkDataTableBuilder::detachDataTable() {
|
| +sk_sp<SkDataTable> SkDataTableBuilder::detachDataTable() {
|
| const int count = fDir.count();
|
| if (0 == count) {
|
| - return SkDataTable::NewEmpty();
|
| + return SkDataTable::MakeEmpty();
|
| }
|
|
|
| // Copy the dir into the heap;
|
| - void* dir = fHeap->alloc(count * sizeof(SkDataTable::Dir),
|
| - SkChunkAlloc::kThrow_AllocFailType);
|
| + void* dir = fHeap->alloc(count * sizeof(SkDataTable::Dir), SkChunkAlloc::kThrow_AllocFailType);
|
| memcpy(dir, fDir.begin(), count * sizeof(SkDataTable::Dir));
|
|
|
| - SkDataTable* table = new SkDataTable((SkDataTable::Dir*)dir, count, chunkalloc_freeproc, fHeap);
|
| + sk_sp<SkDataTable> table(
|
| + new SkDataTable((SkDataTable::Dir*)dir, count, chunkalloc_freeproc, fHeap));
|
| // we have to detach our fHeap, since we are giving that to the table
|
| fHeap = nullptr;
|
| fDir.reset();
|
|
|