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

Side by Side Diff: include/core/SkWriter32.h

Issue 145053003: Have peek32 return uint32_t& to make it harder to look at more than 4 bytes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPictureRecord.cpp » ('j') | src/core/SkPictureRecord.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkWriter32_DEFINED 10 #ifndef SkWriter32_DEFINED
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if (fInternal.isEmpty() && this->externalCount() + count <= fExternalLim it) { 72 if (fInternal.isEmpty() && this->externalCount() + count <= fExternalLim it) {
73 p = fExternal + fCount; 73 p = fExternal + fCount;
74 } else { 74 } else {
75 p = fInternal.append(count); 75 p = fInternal.append(count);
76 } 76 }
77 77
78 fCount += count; 78 fCount += count;
79 return p; 79 return p;
80 } 80 }
81 81
82 // return the address of the 4byte int at the specified offset (which must 82 // Return a reference to the 4 bytes at offset, which must be a multiple of 4.
83 // be a multiple of 4. This does not allocate any new space, so the returned 83 uint32_t& peek32(size_t offset) {
84 // address is only valid for 1 int.
85 uint32_t* peek32(size_t offset) {
86 SkASSERT(SkAlign4(offset) == offset); 84 SkASSERT(SkAlign4(offset) == offset);
87 const int count = SkToInt(offset/4); 85 const int count = SkToInt(offset/4);
88 SkASSERT(count < fCount); 86 SkASSERT(count < fCount);
89 87
90 if (count < this->externalCount()) { 88 if (count < this->externalCount()) {
91 return fExternal + count; 89 return fExternal[count];
92 } 90 }
93 return &fInternal[count - this->externalCount()]; 91 return fInternal[count - this->externalCount()];
94 } 92 }
95 93
96 bool writeBool(bool value) { 94 bool writeBool(bool value) {
97 this->write32(value); 95 this->write32(value);
98 return value; 96 return value;
99 } 97 }
100 98
101 void writeInt(int32_t value) { 99 void writeInt(int32_t value) {
102 this->write32(value); 100 this->write32(value);
103 } 101 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 206
209 /** 207 /**
210 * Computes the size (aligned to multiple of 4) need to write the string 208 * Computes the size (aligned to multiple of 4) need to write the string
211 * in a call to writeString(). If the length is not specified, it will be 209 * in a call to writeString(). If the length is not specified, it will be
212 * computed by calling strlen(). 210 * computed by calling strlen().
213 */ 211 */
214 static size_t WriteStringSize(const char* str, size_t len = (size_t)-1); 212 static size_t WriteStringSize(const char* str, size_t len = (size_t)-1);
215 213
216 /** 214 /**
217 * Move the cursor back to offset bytes from the beginning. 215 * Move the cursor back to offset bytes from the beginning.
218 * This has the same restrictions as peek32: offset must be <= size() and 216 * offset must be a multiple of 4 no greater than size().
219 * offset must be a multiple of 4.
220 */ 217 */
221 void rewindToOffset(size_t offset) { 218 void rewindToOffset(size_t offset) {
222 SkASSERT(SkAlign4(offset) == offset); 219 SkASSERT(SkAlign4(offset) == offset);
223 const int count = SkToInt(offset/4); 220 const int count = SkToInt(offset/4);
224 if (count < this->externalCount()) { 221 if (count < this->externalCount()) {
225 fInternal.setCount(0); 222 fInternal.setCount(0);
226 } else { 223 } else {
227 fInternal.setCount(count - this->externalCount()); 224 fInternal.setCount(count - this->externalCount());
228 } 225 }
229 fCount = count; 226 fCount = count;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 267
271 private: 268 private:
272 union { 269 union {
273 void* fPtrAlignment; 270 void* fPtrAlignment;
274 double fDoubleAlignment; 271 double fDoubleAlignment;
275 char fStorage[SIZE]; 272 char fStorage[SIZE];
276 } fData; 273 } fData;
277 }; 274 };
278 275
279 #endif 276 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPictureRecord.cpp » ('j') | src/core/SkPictureRecord.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698