aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkWriter32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkWriter32.cpp')
-rw-r--r--src/core/SkWriter32.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 1e8a10c87c..041e2fef68 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -67,20 +67,19 @@ size_t SkWriter32::WriteStringSize(const char* str, size_t len) {
return SkAlign4(lenBytes + len + 1);
}
+const size_t kMinBufferBytes = 4096;
+
void SkWriter32::growToAtLeast(size_t size) {
- bool wasExternal = (fExternal != NULL) && (fData == fExternal);
+ const bool wasExternal = (fExternal != NULL) && (fData == fExternal);
+ const size_t minCapacity = kMinBufferBytes +
+ SkTMax(size, fCapacity + (fCapacity >> 1));
+
// cause the buffer to grow
- fInternal.setCount(size);
+ fInternal.setCountExact(minCapacity);
fData = fInternal.begin();
+ fCapacity = fInternal.reserved();
if (wasExternal) {
// we were external, so copy in the data
memcpy(fData, fExternal, fUsed);
}
- // Find out the size the buffer grew to, it may be more than we asked for.
- fCapacity = fInternal.reserved();
- // Expand the array so all reserved space is "used", we maintain the
- // amount we have written manually outside the array
- fInternal.setCount(fCapacity);
- SkASSERT(fInternal.count() == (int)fCapacity);
- SkASSERT(fInternal.reserved() == (int)fCapacity);
}