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.h | |
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.h')
-rw-r--r-- | third_party/gif/SkGifImageReader.h | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/third_party/gif/SkGifImageReader.h b/third_party/gif/SkGifImageReader.h index ebb805e5c5..5b9cdd5ec8 100644 --- a/third_party/gif/SkGifImageReader.h +++ b/third_party/gif/SkGifImageReader.h @@ -52,7 +52,6 @@ class SkGifCodec; #include "SkStreamBuffer.h" #include "../private/SkTArray.h" #include <memory> -#include <vector> typedef SkTArray<unsigned char, true> SkGIFRow; @@ -218,7 +217,7 @@ public: void addLzwBlock(size_t position, size_t size) { - m_lzwBlocks.push_back(SkGIFLZWBlock(position, size)); + m_lzwBlocks.emplace_back(position, size); } bool decode(SkStreamBuffer*, SkGifCodec* client, bool* frameDecoded); @@ -265,7 +264,7 @@ private: std::unique_ptr<SkGIFLZWContext> m_lzwContext; // LZW blocks for this frame. - std::vector<SkGIFLZWBlock> m_lzwBlocks; + SkTArray<SkGIFLZWBlock> m_lzwBlocks; SkGIFColorMap m_localColorMap; @@ -321,7 +320,7 @@ public: int imagesCount() const { - const size_t frames = m_frames.size(); + const int frames = m_frames.count(); if (!frames) { return 0; } @@ -331,7 +330,7 @@ public: // possibly SkGIFImageHeader) but before reading the color table. This // ensures that we do not count a frame before we know its required // frame. - return static_cast<int>(m_frames.back()->reachedStartOfData() ? frames : frames - 1); + return m_frames.back()->reachedStartOfData() ? frames : frames - 1; } int loopCount() const { if (cLoopCountNotSeen == m_loopCount) { @@ -347,12 +346,12 @@ public: const SkGIFFrameContext* frameContext(int index) const { - return index >= 0 && index < static_cast<int>(m_frames.size()) + return index >= 0 && index < m_frames.count() ? m_frames[index].get() : nullptr; } void clearDecodeState() { - for (size_t index = 0; index < m_frames.size(); index++) { + for (int index = 0; index < m_frames.count(); index++) { m_frames[index]->clearDecodeState(); } } @@ -381,7 +380,7 @@ private: void addFrameIfNecessary(); bool currentFrameIsFirstFrame() const { - return m_frames.empty() || (m_frames.size() == 1u && !m_frames[0]->isComplete()); + return m_frames.empty() || (m_frames.count() == 1 && !m_frames[0]->isComplete()); } // Unowned pointer @@ -398,7 +397,7 @@ private: static constexpr int cLoopCountNotSeen = -2; int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders. - std::vector<std::unique_ptr<SkGIFFrameContext>> m_frames; + SkTArray<std::unique_ptr<SkGIFFrameContext>> m_frames; SkStreamBuffer m_streamBuffer; bool m_parseCompleted; |