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

Unified Diff: src/core/SkWriter32.cpp

Issue 130913018: Templetized SkWriter32 readTAt() & overwriteTAt() (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rebased 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 | « src/core/SkWriteBuffer.cpp ('k') | tests/Writer32Test.cpp » ('j') | 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 041e2fef68cff730e1ffccc639210753755cfe6e..46150ee7522ba0f6a45487b0caf790f214d77bcb 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -44,17 +44,13 @@ void SkWriter32::writeString(const char str[], size_t len) {
if ((long)len < 0) {
len = strlen(str);
}
- this->write32(len);
- // add 1 since we also write a terminating 0
- size_t alignedLen = SkAlign4(len + 1);
- char* ptr = (char*)this->reserve(alignedLen);
- {
- // Write the terminating 0 and fill in the rest with zeroes
- uint32_t* padding = (uint32_t*)(ptr + (alignedLen - 4));
- *padding = 0;
- }
- // Copy the string itself.
- memcpy(ptr, str, len);
+
+ // [ 4 byte len ] [ str ... ] [1 - 4 \0s]
+ uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1);
+ *ptr = len;
+ char* chars = (char*)(ptr + 1);
+ memcpy(chars, str, len);
+ chars[len] = '\0';
}
size_t SkWriter32::WriteStringSize(const char* str, size_t len) {
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698