aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkStream.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2016-12-15 14:11:37 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-15 19:49:31 +0000
commit9c457ad27b35022e36d62b6fe1a6aee530213cf6 (patch)
treec06396d0b044d2631b1685d3553406d8f48fd5ae /include/core/SkStream.h
parente4bf164225cc6d027566e9bfa0c8492629a6e090 (diff)
speedup dynamicwstream
- move bytesWritten calculation to query the tail, allowing write() to be faster since it doesn't have to update anything extra per-write. - enforce that all blocks are multiple-of-4 bytes big - update the minimum block size to 4K Before: 30ms After: 23ms for non-4-bytes writes 13ms for 4-bytes writes BUG=skia: Change-Id: Id06ecad3b9fe426747e02accf1393595e3356ce3 Reviewed-on: https://skia-review.googlesource.com/6087 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include/core/SkStream.h')
-rw-r--r--include/core/SkStream.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 089a4ca6f9..e6df9eabde 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -194,11 +194,19 @@ public:
// helpers
- bool write8(U8CPU);
- bool write16(U16CPU);
- bool write32(uint32_t);
+ bool write8(U8CPU value) {
+ uint8_t v = SkToU8(value);
+ return this->write(&v, 1);
+ }
+ bool write16(U16CPU value) {
+ uint16_t v = SkToU16(value);
+ return this->write(&v, 2);
+ }
+ bool write32(uint32_t v) {
+ return this->write(&v, 4);
+ }
- bool writeText(const char text[]) {
+ bool writeText(const char text[]) {
SkASSERT(text);
return this->write(text, strlen(text));
}
@@ -376,10 +384,11 @@ public:
virtual ~SkDynamicMemoryWStream();
bool write(const void* buffer, size_t size) override;
- size_t bytesWritten() const override { return fBytesWritten; }
-
+ size_t bytesWritten() const override;
bool read(void* buffer, size_t offset, size_t size);
- size_t getOffset() const { return fBytesWritten; }
+
+ // Why do we have this as a separate method???
+ size_t getOffset() const { return this->bytesWritten(); }
// copy what has been written to the stream into dst
void copyTo(void* dst) const;
@@ -398,7 +407,13 @@ private:
struct Block;
Block* fHead;
Block* fTail;
- size_t fBytesWritten;
+ size_t fBytesWrittenBeforeTail;
+
+#ifdef SK_DEBUG
+ void validate() const;
+#else
+ void validate() const {}
+#endif
// For access to the Block type.
friend class SkBlockMemoryStream;