From fd918e8c739065fa467cf6614181d3a2c5dcadcb Mon Sep 17 00:00:00 2001 From: yujieqin Date: Tue, 2 Feb 2016 01:21:35 -0800 Subject: [PATCH] Avoid too small reads to bufferMoreData() BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1644893003 Review URL: https://codereview.chromium.org/1644893003 --- src/codec/SkRawCodec.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index da3c28c549..c7de317286 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -267,10 +267,13 @@ private: return false; } - const size_t sizeToRead = newSize - fStreamBuffer.bytesWritten(); - SkAutoTMalloc tempBuffer(sizeToRead); + // Try to read at least 8192 bytes to avoid to many small reads. + const size_t kMinSizeToRead = 8192; + const size_t sizeRequested = newSize - fStreamBuffer.bytesWritten(); + const size_t sizeToRead = SkTMax(kMinSizeToRead, sizeRequested); + SkAutoSTMalloc tempBuffer(sizeToRead); const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); - if (bytesRead != sizeToRead) { + if (bytesRead < sizeRequested) { return false; } return fStreamBuffer.write(tempBuffer.get(), bytesRead); @@ -438,9 +441,6 @@ private: SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { SkAutoTDelete rawStream(new SkRawStream(stream)); ::piex::PreviewImageData imageData; - // FIXME: ::piex::GetPreviewImageData() calls GetData() frequently with small amounts, - // resulting in many calls to bufferMoreData(). Could we make this more efficient by grouping - // smaller requests together? if (::piex::IsRaw(rawStream.get())) { ::piex::Error error = ::piex::GetPreviewImageData(rawStream.get(), &imageData);