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

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

Issue 1339093002: Have SkVarAlloc::alloc() use sk_malloc_throw. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: no, always throw 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 | « no previous file | src/core/SkVarAlloc.h » ('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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 SkASSERT(i < this->count()); 61 SkASSERT(i < this->count());
62 return fRecords[i].mutate<R>(f); 62 return fRecords[i].mutate<R>(f);
63 } 63 }
64 64
65 // TODO: It'd be nice to infer R from F for visit and mutate. 65 // TODO: It'd be nice to infer R from F for visit and mutate.
66 66
67 // Allocate contiguous space for count Ts, to be freed when the SkRecord is destroyed. 67 // Allocate contiguous space for count Ts, to be freed when the SkRecord is destroyed.
68 // Here T can be any class, not just those from SkRecords. Throws on failur e. 68 // Here T can be any class, not just those from SkRecords. Throws on failur e.
69 template <typename T> 69 template <typename T>
70 T* alloc(size_t count = 1) { 70 T* alloc(size_t count = 1) {
71 return (T*)fAlloc.alloc(sizeof(T) * count, SK_MALLOC_THROW); 71 return (T*)fAlloc.alloc(sizeof(T) * count);
72 } 72 }
73 73
74 // Add a new command of type T to the end of this SkRecord. 74 // Add a new command of type T to the end of this SkRecord.
75 // You are expected to placement new an object of type T onto this pointer. 75 // You are expected to placement new an object of type T onto this pointer.
76 template <typename T> 76 template <typename T>
77 T* append() { 77 T* append() {
78 if (fCount == fReserved) { 78 if (fCount == fReserved) {
79 this->grow(); 79 this->grow();
80 } 80 }
81 return fRecords[fCount++].set(this->allocCommand<T>()); 81 return fRecords[fCount++].set(this->allocCommand<T>());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int fCount, fReserved; 189 int fCount, fReserved;
190 SkAutoSTMalloc<kInlineRecords, Record> fRecords; 190 SkAutoSTMalloc<kInlineRecords, Record> fRecords;
191 191
192 // fAlloc needs to be a data structure which can append variable length data in contiguous 192 // fAlloc needs to be a data structure which can append variable length data in contiguous
193 // chunks, returning a stable handle to that data for later retrieval. 193 // chunks, returning a stable handle to that data for later retrieval.
194 SkVarAlloc fAlloc; 194 SkVarAlloc fAlloc;
195 char fInlineAlloc[1 << kInlineAllocLgBytes]; 195 char fInlineAlloc[1 << kInlineAllocLgBytes];
196 }; 196 };
197 197
198 #endif//SkRecord_DEFINED 198 #endif//SkRecord_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkVarAlloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698