Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Unified Diff: src/core/SkDataTable.cpp

Issue 2211143002: Move to SkDataTable::MakeXXX and sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use bare pointer for global. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/ports/SkRemotableFontMgr.h ('k') | src/fonts/SkFontMgr_indirect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « include/ports/SkRemotableFontMgr.h ('k') | src/fonts/SkFontMgr_indirect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698