Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: src/codec/SkRawCodec.cpp

Issue 1644893003: Avoid too small reads to bufferMoreData() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update commit message Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698