diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-08-30 10:09:42 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-30 15:06:54 +0000 |
commit | e750391c349ff1fa1c179fbf2f5af27fb4405cef (patch) | |
tree | 10b5711b4fb8655676e8809109a1fb6dc7dc3b0e /third_party/gif/SkGifImageReader.cpp | |
parent | 64dc4f6d4f73a890f0b2b29e68d7accd664fde87 (diff) |
GIF: Use SkTArray instead of std::vector
Speculative fix for a memory regression seen in Chromium. Chromium
previously used a WTF::Vector, which has a growth factor of 1.5, as does
SkTArray. Depending on the implementation of std::vector, this may slow
the allocation of memory.
Bug: 758946
Change-Id: I323390027467e32a6c66667c927fae0aba292446
Reviewed-on: https://skia-review.googlesource.com/40777
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'third_party/gif/SkGifImageReader.cpp')
-rw-r--r-- | third_party/gif/SkGifImageReader.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/third_party/gif/SkGifImageReader.cpp b/third_party/gif/SkGifImageReader.cpp index ed20af017b..990da5618b 100644 --- a/third_party/gif/SkGifImageReader.cpp +++ b/third_party/gif/SkGifImageReader.cpp @@ -344,7 +344,7 @@ sk_sp<SkColorTable> SkGIFColorMap::buildTable(SkStreamBuffer* streamBuffer, SkCo } sk_sp<SkColorTable> SkGifImageReader::getColorTable(SkColorType colorType, int index) { - if (index < 0 || static_cast<size_t>(index) >= m_frames.size()) { + if (index < 0 || index >= m_frames.count()) { return nullptr; } @@ -382,8 +382,7 @@ bool SkGIFFrameContext::decode(SkStreamBuffer* streamBuffer, SkGifCodec* client, } // Some bad GIFs have extra blocks beyond the last row, which we don't want to decode. - while (static_cast<size_t>(m_currentLzwBlock) < m_lzwBlocks.size() - && m_lzwContext->hasRemainingRows()) { + while (m_currentLzwBlock < m_lzwBlocks.count() && m_lzwContext->hasRemainingRows()) { const auto& block = m_lzwBlocks[m_currentLzwBlock]; const size_t len = block.blockSize; @@ -430,7 +429,7 @@ SkCodec::Result SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query) // SkGIFSizeQuery and SkGIFFrameCountQuery are negative, so this is only meaningful when >= 0. const int lastFrameToParse = (int) query; - if (lastFrameToParse >= 0 && (int) m_frames.size() > lastFrameToParse + if (lastFrameToParse >= 0 && m_frames.count() > lastFrameToParse && m_frames[lastFrameToParse]->isComplete()) { // We have already parsed this frame. return SkCodec::kSuccess; @@ -823,7 +822,7 @@ SkCodec::Result SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query) // decode all rows but we treat it as frame complete. m_frames.back()->setComplete(); GETN(1, SkGIFImageStart); - if (lastFrameToParse >= 0 && (int) m_frames.size() > lastFrameToParse) { + if (lastFrameToParse >= 0 && m_frames.count() > lastFrameToParse) { m_streamBuffer.flush(); return SkCodec::kSuccess; } @@ -874,9 +873,8 @@ bool SkGifImageReader::hasTransparency(int transparentPixel, bool isLocalColorma void SkGifImageReader::addFrameIfNecessary() { if (m_frames.empty() || m_frames.back()->isComplete()) { - const size_t i = m_frames.size(); - std::unique_ptr<SkGIFFrameContext> frame(new SkGIFFrameContext(this, static_cast<int>(i))); - m_frames.push_back(std::move(frame)); + const int i = m_frames.count(); + m_frames.emplace_back(new SkGIFFrameContext(this, i)); } } |