From 43812e24cbb97208d149f419f0c3f61181ba4126 Mon Sep 17 00:00:00 2001 From: bungeman Date: Thu, 17 Mar 2016 09:53:58 -0700 Subject: [PATCH] Revert of free -> reset (patchset #3 id:40001 of https://codereview.chromium.org/1811723002/ ) Reason for revert: Suspect for Win10 failures. Original issue's description: > free -> reset > > The C++ standard library uses ".reset()" where we sometimes write ".free()". > We also use ".reset()" quite a lot. This standardizes on ".reset()". > > This is one more step towards dropping SkAutoTDelete in favor of the standard > std::unique_ptr. > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811723002 > > Committed: https://skia.googlesource.com/skia/+/0e3738db89e86035ed5d4f629bf58b817b1e5274 TBR=reed@google.com,mtklein@google.com,mtklein@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1813843002 --- bench/GrMemoryPoolBench.cpp | 2 +- dm/DMSrcSink.cpp | 2 +- include/core/SkTypes.h | 11 +++++++++-- include/private/SkTemplates.h | 14 ++++++++++++-- src/codec/SkBmpCodec.cpp | 2 +- src/codec/SkJpegCodec.cpp | 2 +- src/codec/SkRawCodec.cpp | 2 +- src/core/SkAdvancedTypefaceMetrics.cpp | 2 +- src/core/SkAdvancedTypefaceMetrics.h | 3 ++- src/gpu/GrGlyph.h | 6 +++--- src/gpu/GrLayerCache.cpp | 2 +- src/gpu/text/GrBatchFontCache.cpp | 2 +- src/images/SkImageDecoder_libwebp.cpp | 2 +- src/pdf/SkPDFDevice.cpp | 4 ++-- src/utils/SkBitSet.cpp | 2 +- src/xml/SkDOM.cpp | 2 +- 16 files changed, 39 insertions(+), 21 deletions(-) diff --git a/bench/GrMemoryPoolBench.cpp b/bench/GrMemoryPoolBench.cpp index f1872fc136..3efe653d8e 100644 --- a/bench/GrMemoryPoolBench.cpp +++ b/bench/GrMemoryPoolBench.cpp @@ -117,7 +117,7 @@ protected: if (nullptr == objects[idx].get()) { objects[idx].reset(new B); } else { - objects[idx].reset(); + objects[idx].free(); } } } diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index e9211e51c2..27cb6aa54e 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1411,7 +1411,7 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri } mojoPicture = SkMojo::FlattenedPicture::New(); mojoPicture->Deserialize(storage.get()); - storage.reset(); + storage.free(); if (!mojoPicture) { return "SkMojo::FlattenedPicture::Deserialize failed"; } diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 1051f08cea..27280d4283 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -519,7 +519,7 @@ public: /** Free the current buffer, and set the internal reference to NULL. Same as calling sk_free(release()) */ - void reset() { + void free() { sk_free(fPtr); fPtr = NULL; } @@ -571,7 +571,7 @@ public: /** * Reallocates the block to a new size. The ptr may or may not change. */ - void* reset(size_t size = 0, OnShrink shrink = kAlloc_OnShrink, bool* didChangeAlloc = NULL) { + void* reset(size_t size, OnShrink shrink = kAlloc_OnShrink, bool* didChangeAlloc = NULL) { if (size == fSize || (kReuse_OnShrink == shrink && size < fSize)) { if (didChangeAlloc) { *didChangeAlloc = false; @@ -589,6 +589,13 @@ public: return fPtr; } + /** + * Releases the block back to the heap + */ + void free() { + this->reset(0); + } + /** * Return the allocated block. */ diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h index e8fbfd5a89..d83ffc8e27 100644 --- a/include/private/SkTemplates.h +++ b/include/private/SkTemplates.h @@ -96,6 +96,7 @@ public: SkAutoTDelete(T* obj = NULL) : std::unique_ptr(obj) {} operator T*() const { return this->get(); } + void free() { this->reset(nullptr); } #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) // Need to update graphics/BitmapRegionDecoder.cpp. @@ -109,6 +110,8 @@ public: template class SkAutoTDeleteArray : public std::unique_ptr { public: SkAutoTDeleteArray(T array[]) : std::unique_ptr(array) {} + + void free() { this->reset(nullptr); } }; /** Allocate an array of T elements, and free the array in the destructor @@ -283,9 +286,9 @@ public: } /** Resize the memory area pointed to by the current ptr without preserving contents. */ - T* reset(size_t count = 0) { + T* reset(size_t count) { sk_free(fPtr); - fPtr = count ? (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW) : nullptr; + fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW); return fPtr; } @@ -307,6 +310,13 @@ public: return fPtr[index]; } + /** + * Releases the block back to the heap + */ + void free() { + this->reset(0); + } + /** * Transfer ownership of the ptr to the caller, setting the internal * pointer to NULL. Note that this differs from get(), which also returns diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp index e327f79018..32f1d15277 100644 --- a/src/codec/SkBmpCodec.cpp +++ b/src/codec/SkBmpCodec.cpp @@ -392,7 +392,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { alphaType = kUnpremul_SkAlphaType; } } - iBuffer.reset(); + iBuffer.free(); // Additionally, 32 bit bmp-in-icos use the alpha channel. // FIXME (msarett): Don't all bmp-in-icos use the alpha channel? diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index a342cd8b6a..2534a5f123 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -413,7 +413,7 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, // Remove objects used for sampling. fSwizzler.reset(nullptr); fSrcRow = nullptr; - fStorage.reset(); + fStorage.free(); // Now, given valid output dimensions, we can start the decompress if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index 3b7b9a96ee..208bd8952d 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -381,7 +381,7 @@ public: if (fStream->getMemoryBase()) { // directly copy if getMemoryBase() is available. SkAutoTUnref data(SkData::NewWithCopy( static_cast(fStream->getMemoryBase()) + offset, bytesToRead)); - fStream.reset(); + fStream.free(); return new SkMemoryStream(data); } else { SkAutoTUnref data(SkData::NewUninitialized(bytesToRead)); diff --git a/src/core/SkAdvancedTypefaceMetrics.cpp b/src/core/SkAdvancedTypefaceMetrics.cpp index 28079f98e9..b5b49e3ac5 100644 --- a/src/core/SkAdvancedTypefaceMetrics.cpp +++ b/src/core/SkAdvancedTypefaceMetrics.cpp @@ -245,7 +245,7 @@ SkAdvancedTypefaceMetrics::AdvanceMetric* getAdvanceData( if (curRange->fStartId == lastIndex) { SkASSERT(prevRange); SkASSERT(prevRange->fNext->fStartId == lastIndex); - prevRange->fNext.reset(); + prevRange->fNext.free(); } else { finishRange(curRange, lastIndex - 1, SkAdvancedTypefaceMetrics::WidthRange::kRange); diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h index 424e5f3f51..92655d21b2 100644 --- a/src/core/SkAdvancedTypefaceMetrics.h +++ b/src/core/SkAdvancedTypefaceMetrics.h @@ -28,12 +28,13 @@ public: T* get() const { return fPtr; } T* operator->() const { return fPtr; } - void reset(T* ptr = nullptr) { + void reset(T* ptr) { if (ptr != fPtr) { delete fPtr; fPtr = ptr; } } + void free() { this->reset(nullptr); } T* release() { T* ptr = fPtr; fPtr = nullptr; diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h index fb998a4947..55e925f09d 100644 --- a/src/gpu/GrGlyph.h +++ b/src/gpu/GrGlyph.h @@ -28,7 +28,7 @@ struct GrGlyph { kCoverage_MaskStyle, kDistance_MaskStyle }; - + typedef uint32_t PackedID; GrBatchAtlas::AtlasID fID; @@ -49,7 +49,7 @@ struct GrGlyph { fTooLargeForAtlas = GrBatchAtlas::GlyphTooLargeForAtlas(bounds.width(), bounds.height()); } - void reset() { + void free() { if (fPath) { delete fPath; fPath = nullptr; @@ -86,7 +86,7 @@ struct GrGlyph { static inline MaskStyle UnpackMaskStyle(PackedID packed) { return ((packed >> 20) & 1) ? kDistance_MaskStyle : kCoverage_MaskStyle; } - + static inline uint16_t UnpackID(PackedID packed) { return (uint16_t)packed; } diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index 3c7ab88735..c2facbb12d 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -98,7 +98,7 @@ GrLayerCache::~GrLayerCache() { SkASSERT(0 == fPictureHash.count()); // The atlas only lets go of its texture when the atlas is deleted. - fAtlas.reset(); + fAtlas.free(); } void GrLayerCache::initAtlas() { diff --git a/src/gpu/text/GrBatchFontCache.cpp b/src/gpu/text/GrBatchFontCache.cpp index 97c55e28ad..d99df1da03 100644 --- a/src/gpu/text/GrBatchFontCache.cpp +++ b/src/gpu/text/GrBatchFontCache.cpp @@ -165,7 +165,7 @@ GrBatchTextStrike::GrBatchTextStrike(GrBatchFontCache* cache, const GrFontDescKe GrBatchTextStrike::~GrBatchTextStrike() { SkTDynamicHash::Iter iter(&fCache); while (!iter.done()) { - (*iter).reset(); + (*iter).free(); ++iter; } } diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index 2db08cee83..52535779fa 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -224,7 +224,7 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) { break; } } while (VP8_STATUS_OK != status); - srcStorage.reset(); + srcStorage.free(); WebPIDelete(idec); WebPFreeDecBuffer(&config->output); diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 443bb1aedf..94a103aeb1 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -732,9 +732,9 @@ SkPDFDevice::~SkPDFDevice() { } void SkPDFDevice::init() { - fContentEntries.reset(); + fContentEntries.free(); fLastContentEntry = nullptr; - fMarginContentEntries.reset(); + fMarginContentEntries.free(); fLastMarginContentEntry = nullptr; fDrawingArea = kContent_DrawingArea; if (fFontGlyphUsage.get() == nullptr) { diff --git a/src/utils/SkBitSet.cpp b/src/utils/SkBitSet.cpp index 985bb6eed0..3ace15de80 100755 --- a/src/utils/SkBitSet.cpp +++ b/src/utils/SkBitSet.cpp @@ -27,7 +27,7 @@ SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) { return *this; } fBitCount = rhs.fBitCount; - fBitData.reset(); + fBitData.free(); fDwordCount = rhs.fDwordCount; fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t))); memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t)); diff --git a/src/xml/SkDOM.cpp b/src/xml/SkDOM.cpp index 8b55f6c980..0f0b614f11 100644 --- a/src/xml/SkDOM.cpp +++ b/src/xml/SkDOM.cpp @@ -374,7 +374,7 @@ SkXMLParser* SkDOM::beginParsing() { const SkDOM::Node* SkDOM::finishParsing() { SkASSERT(fParser); fRoot = fParser->getRoot(); - fParser.reset(); + fParser.free(); return fRoot; } -- 2.34.1