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
This commit is contained in:
yujieqin 2016-02-02 01:21:35 -08:00 committed by Commit bot
parent be0fcb10f1
commit fd918e8c73

View File

@ -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);