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

Unified Diff: src/core/SkStream.cpp

Issue 1044953002: Add a method to read a stream without advancing it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: No half measures, Walter. Created 5 years, 9 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
Index: src/core/SkStream.cpp
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index 426f5569e887fe83e4aee8b38c412587abfa1fe2..2a07a114397c4b342a04abba3f3258af33b32682 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -367,6 +367,23 @@ size_t SkMemoryStream::read(void* buffer, size_t size) {
return size;
}
+bool SkMemoryStream::peek(void* buffer, size_t size) const {
+ SkASSERT(buffer != NULL);
+ const size_t position = fOffset;
+ if (size > fData->size() - position) {
+ // The stream is not large enough to satisfy this request.
+ return false;
+ }
+ SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this);
+#ifdef SK_DEBUG
bungeman-skia 2015/04/02 18:24:09 Should this be SkDEBUGCODE(...) instead? Then it w
scroggo 2015/04/02 19:49:43 Yes. Much better.
+ const size_t bytesRead =
+#endif
+ nonConstThis->read(buffer, size);
+ SkASSERT(bytesRead == size);
+ nonConstThis->fOffset = position;
+ return true;
+}
+
bool SkMemoryStream::isAtEnd() const {
return fOffset == fData->size();
}

Powered by Google App Engine
This is Rietveld 408576698