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

Unified Diff: src/core/SkWriter32.cpp

Issue 158953003: Reland SkWriter32 growth change with build fixes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: small things Created 6 years, 10 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
« no previous file with comments | « include/core/SkWriter32.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkWriter32.cpp
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 1e8a10c87caceffa61045fbf1fe0524dfb92ff4e..041e2fef68cff730e1ffccc639210753755cfe6e 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);
}
« no previous file with comments | « include/core/SkWriter32.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698