diff --git a/include/core/SkSpan.h b/include/core/SkSpan.h index b09ec867a0..9487e9e222 100644 --- a/include/core/SkSpan.h +++ b/include/core/SkSpan.h @@ -33,11 +33,8 @@ public: constexpr SkSpan(const SkSpan& that) : fPtr(that.data()), fSize{that.size()} {} constexpr SkSpan(const SkSpan& o) = default; - constexpr SkSpan& operator=(const SkSpan& that) { - fPtr = that.fPtr; - fSize = that.fSize; - return *this; - } + constexpr SkSpan& operator=(const SkSpan& that) = default; + constexpr T& operator [] (size_t i) const { SkASSERT(i < this->size()); return fPtr[i]; diff --git a/src/core/SkPaintParamsKey.cpp b/src/core/SkPaintParamsKey.cpp index 460b65fad2..0e5f4a64ba 100644 --- a/src/core/SkPaintParamsKey.cpp +++ b/src/core/SkPaintParamsKey.cpp @@ -58,7 +58,6 @@ void SkPaintParamsKeyBuilder::beginBlock(int codeSnippetID) { SkASSERT(!this->isLocked()); - fData.reserve_back(SkPaintParamsKey::kBlockHeaderSizeInBytes); fStack.push_back({ codeSnippetID, this->sizeInBytes(), SkDEBUGCODE(kHeaderExpectations, 0) }); @@ -102,7 +101,7 @@ void SkPaintParamsKeyBuilder::endBlock() { fData[headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes] = blockSize; - fStack.pop_back(); + fStack.pop(); #ifdef SK_DEBUG if (!fStack.empty()) { @@ -140,7 +139,7 @@ void SkPaintParamsKeyBuilder::addBytes(uint32_t numBytes, const uint8_t* data) { SkASSERT(!this->isLocked()); - fData.push_back_n(numBytes, data); + fData.append(numBytes, data); } SkPaintParamsKey SkPaintParamsKeyBuilder::lockAsKey() { @@ -154,17 +153,17 @@ SkPaintParamsKey SkPaintParamsKeyBuilder::lockAsKey() { // Partially reset for reuse. Note that the key resulting from this call will be holding a lock // on this builder and must be deleted before this builder is fully reset. fIsValid = true; - fStack.clear(); + fStack.rewind(); - return SkPaintParamsKey(SkMakeSpan(fData.data(), fData.count()), this); + return SkPaintParamsKey(SkMakeSpan(fData.begin(), fData.count()), this); } void SkPaintParamsKeyBuilder::makeInvalid() { SkASSERT(fIsValid); SkASSERT(!this->isLocked()); - fStack.clear(); - fData.reset(); + fStack.rewind(); + fData.rewind(); this->beginBlock(SkBuiltInCodeSnippetID::kError); this->endBlock(); diff --git a/src/core/SkPaintParamsKey.h b/src/core/SkPaintParamsKey.h index 8f716f7412..f244d70a76 100644 --- a/src/core/SkPaintParamsKey.h +++ b/src/core/SkPaintParamsKey.h @@ -10,12 +10,11 @@ #include "include/core/SkSpan.h" #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/SkTDArray.h" #include "src/core/SkBuiltInCodeSnippetID.h" #include #include -#include enum class SkBackend : uint8_t { kGanesh, @@ -195,7 +194,7 @@ public: void unlock() { SkASSERT(fLocked); - fData.reset(); + fData.rewind(); SkDEBUGCODE(fLocked = false;) SkDEBUGCODE(this->checkReset();) } @@ -215,15 +214,18 @@ private: #endif }; - bool fIsValid = true; const SkShaderCodeDictionary* fDict; - const SkBackend fBackend; - std::vector fStack; - // TODO: It is probably overkill but we could encode the SkBackend in the first byte of // the key. + const SkBackend fBackend; + + bool fIsValid = true; SkDEBUGCODE(bool fLocked = false;) - SkTArray fData; + + // Use SkTDArray so that we can guarantee that rewind() preserves the underlying storage and + // repeated use of the builder will hit a high-water mark and avoid lots of allocations. + SkTDArray fStack; + SkTDArray fData; }; #endif // SkPaintParamsKey_DEFINED