aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRWBuffer.h
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-09-30 13:34:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-30 13:34:19 -0700
commit5776508126534db2af97d560588e7046e745df65 (patch)
tree2925a45e91f235ebe6b8413191d7cf5ddda44dda /include/core/SkRWBuffer.h
parentf6566314f84feaf7906fe89ac9cab694dfd75451 (diff)
Add a SkRWBuffer reserve mechanism
Currently, Chromium stores segmented data in a SharedBuffer and appends to SkRWBuffer one segment at a time: const char* segment = 0; for (size_t length = data->getSomeData(segment, m_rwBuffer->size()); length; length = data->getSomeData(segment, m_rwBuffer->size())) { m_rwBuffer->append(segment, length, remaining); } This can yield a bunch of just-above-4k allocations => wasted RAM due to internal fragmentation. Ideally, we'd want a SkRWBuffer::reserve(size_t bytes) API, but the current internals don't support that trivially. Alternatively, the caller can pass a reserve hint at append() time. BUG=chromium:651698 R=scroggo@google.com,reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2385803002 Review-Url: https://codereview.chromium.org/2385803002
Diffstat (limited to 'include/core/SkRWBuffer.h')
-rw-r--r--include/core/SkRWBuffer.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/include/core/SkRWBuffer.h b/include/core/SkRWBuffer.h
index 9626d28df9..451933f353 100644
--- a/include/core/SkRWBuffer.h
+++ b/include/core/SkRWBuffer.h
@@ -79,7 +79,15 @@ public:
~SkRWBuffer();
size_t size() const { return fTotalUsed; }
- void append(const void* buffer, size_t length);
+
+ /**
+ * Append |length| bytes from |buffer|.
+ *
+ * If the caller knows in advance how much more data they are going to append, they can
+ * pass a |reserve| hint (representing the number of upcoming bytes *in addition* to the
+ * current append), to minimize the number of internal allocations.
+ */
+ void append(const void* buffer, size_t length, size_t reserve = 0);
SkROBuffer* newRBufferSnapshot() const;
SkStreamAsset* newStreamSnapshot() const;