Index: src/utils/SkFrontBufferedStream.cpp |
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp |
index d44389b7c81ad4c8bdfd625b4f0c29d2625a6742..8cb3931082c75d268e793212a73f688a1dbe227f 100644 |
--- a/src/utils/SkFrontBufferedStream.cpp |
+++ b/src/utils/SkFrontBufferedStream.cpp |
@@ -24,14 +24,16 @@ public: |
virtual size_t getPosition() const SK_OVERRIDE { return fOffset; } |
- virtual bool hasLength() const SK_OVERRIDE; |
+ virtual bool hasLength() const SK_OVERRIDE { return fHasLength; } |
- virtual size_t getLength() const SK_OVERRIDE; |
+ virtual size_t getLength() const SK_OVERRIDE { return fLength; } |
virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } |
private: |
SkAutoTUnref<SkStream> fStream; |
+ const bool fHasLength; |
+ const size_t fLength; |
// Current offset into the stream. Always >= 0. |
size_t fOffset; |
// Amount that has been buffered by calls to read. Will always be less than |
@@ -70,6 +72,8 @@ SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe |
FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) |
: fStream(SkRef(stream)) |
+ , fHasLength(stream->hasPosition() && stream->hasLength()) |
+ , fLength(stream->getLength() - stream->getPosition()) |
, fOffset(0) |
, fBufferedSoFar(0) |
, fBufferSize(bufferSize) |
@@ -94,14 +98,6 @@ bool FrontBufferedStream::rewind() { |
return false; |
} |
-bool FrontBufferedStream::hasLength() const { |
- return fStream->hasLength(); |
-} |
- |
-size_t FrontBufferedStream::getLength() const { |
- return fStream->getLength(); |
-} |
- |
size_t FrontBufferedStream::readFromBuffer(char* dst, size_t size) { |
SkASSERT(fOffset < fBufferedSoFar); |
// Some data has already been copied to fBuffer. Read up to the |