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

Side by Side Diff: src/core/SkRecord.h

Issue 517073002: Align all SkRecord::alloc() calls up to at least a pointer size. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkAlignPtr Created 6 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 | « include/core/SkTypes.h ('k') | tests/RecordTest.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 2014 Google Inc. 2 * Copyright 2014 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 #ifndef SkRecord_DEFINED 8 #ifndef SkRecord_DEFINED
9 #define SkRecord_DEFINED 9 #define SkRecord_DEFINED
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 R mutate(unsigned i, F& f) { 58 R mutate(unsigned i, F& f) {
59 SkASSERT(i < this->count()); 59 SkASSERT(i < this->count());
60 return fRecords[i].mutate<R>(fTypes[i], f); 60 return fRecords[i].mutate<R>(fTypes[i], f);
61 } 61 }
62 // TODO: It'd be nice to infer R from F for visit and mutate if we ever get std::result_of. 62 // TODO: It'd be nice to infer R from F for visit and mutate if we ever get std::result_of.
63 63
64 // Allocate contiguous space for count Ts, to be freed when the SkRecord is destroyed. 64 // Allocate contiguous space for count Ts, to be freed when the SkRecord is destroyed.
65 // Here T can be any class, not just those from SkRecords. Throws on failur e. 65 // Here T can be any class, not just those from SkRecords. Throws on failur e.
66 template <typename T> 66 template <typename T>
67 T* alloc(size_t count = 1) { 67 T* alloc(size_t count = 1) {
68 return (T*)fAlloc.allocThrow(sizeof(T) * count); 68 // Bump up to the next pointer width if needed, so all allocations start pointer-aligned.
69 return (T*)fAlloc.allocThrow(SkAlignPtr(sizeof(T) * count));
69 } 70 }
70 71
71 // Add a new command of type T to the end of this SkRecord. 72 // Add a new command of type T to the end of this SkRecord.
72 // You are expected to placement new an object of type T onto this pointer. 73 // You are expected to placement new an object of type T onto this pointer.
73 template <typename T> 74 template <typename T>
74 T* append() { 75 T* append() {
75 if (fCount == fReserved) { 76 if (fCount == fReserved) {
76 fReserved = SkTMax(kFirstReserveCount, fReserved*2); 77 fReserved = SkTMax(kFirstReserveCount, fReserved*2);
77 fRecords.realloc(fReserved); 78 fRecords.realloc(fReserved);
78 fTypes.realloc(fReserved); 79 fTypes.realloc(fReserved);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 SkChunkAlloc fAlloc; 226 SkChunkAlloc fAlloc;
226 SkAutoTMalloc<Record> fRecords; 227 SkAutoTMalloc<Record> fRecords;
227 SkAutoTMalloc<Type8> fTypes; 228 SkAutoTMalloc<Type8> fTypes;
228 // fCount and fReserved measure both fRecords and fTypes, which always grow in lock step. 229 // fCount and fReserved measure both fRecords and fTypes, which always grow in lock step.
229 unsigned fCount; 230 unsigned fCount;
230 unsigned fReserved; 231 unsigned fReserved;
231 const unsigned kFirstReserveCount; 232 const unsigned kFirstReserveCount;
232 }; 233 };
233 234
234 #endif//SkRecord_DEFINED 235 #endif//SkRecord_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkTypes.h ('k') | tests/RecordTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698