Specialize SkOncePtr<T[]>.
SkOncePtr<T[]> is identical to SkOncePtr<T> except we'll default to delete[] for cleanup. CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot BUG=skia: No public API changes. TBR=reed@google.com Review URL: https://codereview.chromium.org/1311893010
This commit is contained in:
parent
af2533a165
commit
9a50174dbc
@ -61,10 +61,8 @@ private:
|
||||
// assumes ownership of colors (assumes it was allocated w/ malloc)
|
||||
SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc);
|
||||
|
||||
struct Free16BitCache { void operator()(uint16_t* cache) const { sk_free(cache); } };
|
||||
|
||||
SkPMColor* fColors;
|
||||
SkOncePtr<uint16_t, Free16BitCache> f16BitCache;
|
||||
SkOncePtr<uint16_t[]> f16BitCache;
|
||||
int fCount;
|
||||
|
||||
void init(const SkPMColor* colors, int count);
|
||||
|
@ -40,6 +40,10 @@ private:
|
||||
SkBaseOncePtr<T> fOnce;
|
||||
};
|
||||
|
||||
// If you ask for SkOncePtr<T[]>, we'll clean up with delete[] by default.
|
||||
template <typename T>
|
||||
class SkOncePtr<T[]> : public SkOncePtr<T, skstd::default_delete<T[]>> {};
|
||||
|
||||
/* TODO(mtklein): in next CL
|
||||
typedef SkBaseOncePtr<void> SkOnceFlag;
|
||||
#define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name
|
||||
|
@ -49,7 +49,7 @@ SkColorTable::~SkColorTable() {
|
||||
|
||||
const uint16_t* SkColorTable::read16BitCache() const {
|
||||
return f16BitCache.get([&]{
|
||||
uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
|
||||
auto cache = new uint16_t[fCount];
|
||||
for (int i = 0; i < fCount; i++) {
|
||||
cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user