diff --git a/include/core/SkDataTable.h b/include/core/SkDataTable.h index 0c92d7f52e..f8aba9a559 100644 --- a/include/core/SkDataTable.h +++ b/include/core/SkDataTable.h @@ -8,7 +8,6 @@ #ifndef SkDataTable_DEFINED #define SkDataTable_DEFINED -#include "../private/SkChunkAlloc.h" #include "../private/SkTDArray.h" #include "SkData.h" #include "SkString.h" @@ -117,58 +116,4 @@ private: typedef SkRefCnt INHERITED; }; -/** - * Helper class that allows for incrementally building up the data needed to - * create a SkDataTable. - */ -class SK_API SkDataTableBuilder : SkNoncopyable { -public: - SkDataTableBuilder(size_t minChunkSize); - ~SkDataTableBuilder(); - - int count() const { return fDir.count(); } - size_t minChunkSize() const { return fMinChunkSize; } - - /** - * Forget any previously appended entries, setting count() back to 0. - */ - void reset(size_t minChunkSize); - void reset() { - this->reset(fMinChunkSize); - } - - /** - * Copy size-bytes from data, and append it to the growing SkDataTable. - */ - void append(const void* data, size_t size); - - /** - * Helper version of append() passes strlen() + 1 for the size, - * so the trailing-zero will be copied as well. - */ - void appendStr(const char str[]) { - this->append(str, strlen(str) + 1); - } - - /** - * Helper version of append() passes string.size() + 1 for the size, - * so the trailing-zero will be copied as well. - */ - void appendString(const SkString& string) { - this->append(string.c_str(), string.size() + 1); - } - - /** - * Return an SkDataTable from the accumulated entries that were added by - * calls to append(). This call also clears any accumluated entries from - * this builder, so its count() will be 0 after this call. - */ - sk_sp detachDataTable(); - -private: - SkTDArray fDir; - SkChunkAlloc* fHeap; - size_t fMinChunkSize; -}; - #endif diff --git a/src/core/SkDataTable.cpp b/src/core/SkDataTable.cpp index ea2b91b903..e80ba8f2b5 100644 --- a/src/core/SkDataTable.cpp +++ b/src/core/SkDataTable.cpp @@ -129,53 +129,3 @@ sk_sp SkDataTable::MakeArrayProc(const void* array, size_t elemSize } return sk_sp(new SkDataTable(array, elemSize, count, proc, ctx)); } - -/////////////////////////////////////////////////////////////////////////////// - -static void chunkalloc_freeproc(void* context) { delete (SkChunkAlloc*)context; } - -SkDataTableBuilder::SkDataTableBuilder(size_t minChunkSize) - : fHeap(nullptr) - , fMinChunkSize(minChunkSize) {} - -SkDataTableBuilder::~SkDataTableBuilder() { this->reset(); } - -void SkDataTableBuilder::reset(size_t minChunkSize) { - fMinChunkSize = minChunkSize; - fDir.reset(); - if (fHeap) { - delete fHeap; - fHeap = nullptr; - } -} - -void SkDataTableBuilder::append(const void* src, size_t size) { - if (nullptr == fHeap) { - fHeap = new SkChunkAlloc(fMinChunkSize); - } - - void* dst = fHeap->alloc(size, SkChunkAlloc::kThrow_AllocFailType); - memcpy(dst, src, size); - - SkDataTable::Dir* dir = fDir.append(); - dir->fPtr = dst; - dir->fSize = size; -} - -sk_sp SkDataTableBuilder::detachDataTable() { - const int count = fDir.count(); - if (0 == count) { - return SkDataTable::MakeEmpty(); - } - - // Copy the dir into the heap; - void* dir = fHeap->alloc(count * sizeof(SkDataTable::Dir), SkChunkAlloc::kThrow_AllocFailType); - memcpy(dir, fDir.begin(), count * sizeof(SkDataTable::Dir)); - - sk_sp 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(); - return table; -} diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp index d6e994cb65..d0cafc3dde 100644 --- a/tests/DataRefTest.cpp +++ b/tests/DataRefTest.cpp @@ -85,32 +85,6 @@ static void test_vartable(skiatest::Reporter* reporter) { } } -static void test_tablebuilder(skiatest::Reporter* reporter) { - const char* str[] = { - "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" - }; - int count = SK_ARRAY_COUNT(str); - - SkDataTableBuilder builder(16); - - for (int i = 0; i < count; ++i) { - builder.append(str[i], strlen(str[i]) + 1); - } - sk_sp table(builder.detachDataTable()); - - REPORTER_ASSERT(reporter, table->count() == count); - for (int i = 0; i < count; ++i) { - size_t size; - REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1); - REPORTER_ASSERT(reporter, !strcmp(table->atT(i, &size), - str[i])); - REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1); - - const char* s = table->atStr(i); - REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); - } -} - static void test_globaltable(skiatest::Reporter* reporter) { static const int gData[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 @@ -133,7 +107,6 @@ DEF_TEST(DataTable, reporter) { test_emptytable(reporter); test_simpletable(reporter); test_vartable(reporter); - test_tablebuilder(reporter); test_globaltable(reporter); }