Index: src/codec/SkRawCodec.cpp |
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp |
index da3c28c549ff617cc74df0effb9ff18177eca023..c7de3172863876cdbf1ec0e2d5a2d0111e6ddc3f 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<uint8> 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<kMinSizeToRead, uint8> 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<SkRawStream> 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); |