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

Unified Diff: src/core/SkWriter32.cpp

Issue 130913018: Templetized SkWriter32 readTAt() & overwriteTAt() (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Refactored writeString, reservePad. 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
Index: src/core/SkWriter32.cpp
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 5e89ed655b70e5d83da4df2588704689898b52e6..fe6e69f4670a803b6863e67f395b2b4f2bbf9221 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) {

Powered by Google App Engine
This is Rietveld 408576698