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

Side by Side Diff: src/core/SkWriter32.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 size_t SkReader32::readIntoString(SkString* copy) { 30 size_t SkReader32::readIntoString(SkString* copy) {
31 size_t len; 31 size_t len;
32 const char* ptr = this->readString(&len); 32 const char* ptr = this->readString(&len);
33 if (copy) { 33 if (copy) {
34 copy->set(ptr, len); 34 copy->set(ptr, len);
35 } 35 }
36 return len; 36 return len;
37 } 37 }
38 38
39 void SkWriter32::writeString(const char str[], size_t len) { 39 void SkWriter32::writeString(const char str[], size_t len) {
40 if (NULL == str) { 40 if (nullptr == 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 = SkToU32(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 }
61 const size_t lenBytes = 4; // we use 4 bytes to record the length 61 const size_t lenBytes = 4; // we use 4 bytes to record the length
62 // add 1 since we also write a terminating 0 62 // add 1 since we also write a terminating 0
63 return SkAlign4(lenBytes + len + 1); 63 return SkAlign4(lenBytes + len + 1);
64 } 64 }
65 65
66 void SkWriter32::growToAtLeast(size_t size) { 66 void SkWriter32::growToAtLeast(size_t size) {
67 const bool wasExternal = (fExternal != NULL) && (fData == fExternal); 67 const bool wasExternal = (fExternal != nullptr) && (fData == fExternal);
68 68
69 fCapacity = 4096 + SkTMax(size, fCapacity + (fCapacity / 2)); 69 fCapacity = 4096 + SkTMax(size, fCapacity + (fCapacity / 2));
70 fInternal.realloc(fCapacity); 70 fInternal.realloc(fCapacity);
71 fData = fInternal.get(); 71 fData = fInternal.get();
72 72
73 if (wasExternal) { 73 if (wasExternal) {
74 // we were external, so copy in the data 74 // we were external, so copy in the data
75 memcpy(fData, fExternal, fUsed); 75 memcpy(fData, fExternal, fUsed);
76 } 76 }
77 } 77 }
78 78
79 SkData* SkWriter32::snapshotAsData() const { 79 SkData* SkWriter32::snapshotAsData() const {
80 return SkData::NewWithCopy(fData, fUsed); 80 return SkData::NewWithCopy(fData, fUsed);
81 } 81 }
OLDNEW
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698