diff options
author | fmalita <fmalita@chromium.org> | 2016-09-30 13:34:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-30 13:34:19 -0700 |
commit | 5776508126534db2af97d560588e7046e745df65 (patch) | |
tree | 2925a45e91f235ebe6b8413191d7cf5ddda44dda /include | |
parent | f6566314f84feaf7906fe89ac9cab694dfd75451 (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')
-rw-r--r-- | include/core/SkRWBuffer.h | 10 |
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; |