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

Unified Diff: src/core/SkWriter32.cpp

Issue 156683004: Cleaner external buffer handling in SkWriter32 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Review fixes (spaced and comments) 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
« include/core/SkWriter32.h ('K') | « 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 5e89ed655b70e5d83da4df2588704689898b52e6..07a43d782123b8bfb70ec34fb2a48f8a437eea01 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -66,3 +66,18 @@ size_t SkWriter32::WriteStringSize(const char* str, size_t len) {
// add 1 since we also write a terminating 0
return SkAlign4(lenBytes + len + 1);
}
+
+void SkWriter32::grow(size_t size) {
+ bool wasExternal = (fExternal != NULL) && (fData == fExternal);
+ // cause the buffer to grow
+ fInternal.setCount(size);
+ fData = fInternal.begin();
+ if (wasExternal) {
+ // we were external, so copy in the data
+ memcpy(fData, fExternal, fUsed);
+ }
+ // read the grown capacity
+ fCapacity = fInternal.reserved();
+ // expand the buffer to it's full capacity
mtklein 2014/02/06 22:01:24 Can you just add another half sentence explaining
iancottrell 2014/02/07 12:20:41 Done.
iancottrell 2014/02/07 12:20:41 Done.
iancottrell 2014/02/07 12:20:41 Done. This is changing again in the next cl, where
+ fInternal.setCount(fCapacity);
+}
mtklein 2014/02/06 22:01:24 Can you add an SkASSERT(fInternal.reserved() ==
iancottrell 2014/02/07 12:20:41 Done.
iancottrell 2014/02/07 12:20:41 Done.
« include/core/SkWriter32.h ('K') | « include/core/SkWriter32.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698