| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkReader32.h" | 8 #include "SkReader32.h" |
| 9 #include "SkString.h" | 9 #include "SkString.h" |
| 10 #include "SkWriter32.h" | 10 #include "SkWriter32.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 if (NULL == str) { | 40 if (NULL == str) { |
| 41 str = ""; | 41 str = ""; |
| 42 len = 0; | 42 len = 0; |
| 43 } | 43 } |
| 44 if ((long)len < 0) { | 44 if ((long)len < 0) { |
| 45 len = strlen(str); | 45 len = strlen(str); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // [ 4 byte len ] [ str ... ] [1 - 4 \0s] | 48 // [ 4 byte len ] [ str ... ] [1 - 4 \0s] |
| 49 uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1); | 49 uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1); |
| 50 *ptr = len; | 50 *ptr = SkToU32(len); |
| 51 char* chars = (char*)(ptr + 1); | 51 char* chars = (char*)(ptr + 1); |
| 52 memcpy(chars, str, len); | 52 memcpy(chars, str, len); |
| 53 chars[len] = '\0'; | 53 chars[len] = '\0'; |
| 54 } | 54 } |
| 55 | 55 |
| 56 size_t SkWriter32::WriteStringSize(const char* str, size_t len) { | 56 size_t SkWriter32::WriteStringSize(const char* str, size_t len) { |
| 57 if ((long)len < 0) { | 57 if ((long)len < 0) { |
| 58 SkASSERT(str); | 58 SkASSERT(str); |
| 59 len = strlen(str); | 59 len = strlen(str); |
| 60 } | 60 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // prepare us to do copy on write, by pretending the data buffer | 96 // prepare us to do copy on write, by pretending the data buffer |
| 97 // is external and size limited | 97 // is external and size limited |
| 98 mutable_this.fData = buffer; | 98 mutable_this.fData = buffer; |
| 99 mutable_this.fCapacity = fUsed; | 99 mutable_this.fCapacity = fUsed; |
| 100 mutable_this.fExternal = buffer; | 100 mutable_this.fExternal = buffer; |
| 101 } | 101 } |
| 102 mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed)); | 102 mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed)); |
| 103 } | 103 } |
| 104 return SkRef(fSnapshot.get()); // Take an extra ref for the caller. | 104 return SkRef(fSnapshot.get()); // Take an extra ref for the caller. |
| 105 } | 105 } |
| OLD | NEW |