| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 GrAllocator_DEFINED | 8 #ifndef GrAllocator_DEFINED |
| 9 #define GrAllocator_DEFINED | 9 #define GrAllocator_DEFINED |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 explicit GrTAllocator(int itemsPerBlock) | 237 explicit GrTAllocator(int itemsPerBlock) |
| 238 : fAllocator(sizeof(T), itemsPerBlock, NULL) {} | 238 : fAllocator(sizeof(T), itemsPerBlock, NULL) {} |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Adds an item and returns it. | 241 * Adds an item and returns it. |
| 242 * | 242 * |
| 243 * @return the added item. | 243 * @return the added item. |
| 244 */ | 244 */ |
| 245 T& push_back() { | 245 T& push_back() { |
| 246 void* item = fAllocator.push_back(); | 246 void* item = fAllocator.push_back(); |
| 247 SkASSERT(NULL != item); | 247 SkASSERT(item); |
| 248 SkNEW_PLACEMENT(item, T); | 248 SkNEW_PLACEMENT(item, T); |
| 249 return *(T*)item; | 249 return *(T*)item; |
| 250 } | 250 } |
| 251 | 251 |
| 252 T& push_back(const T& t) { | 252 T& push_back(const T& t) { |
| 253 void* item = fAllocator.push_back(); | 253 void* item = fAllocator.push_back(); |
| 254 SkASSERT(NULL != item); | 254 SkASSERT(item); |
| 255 SkNEW_PLACEMENT_ARGS(item, T, (t)); | 255 SkNEW_PLACEMENT_ARGS(item, T, (t)); |
| 256 return *(T*)item; | 256 return *(T*)item; |
| 257 } | 257 } |
| 258 | 258 |
| 259 /** | 259 /** |
| 260 * Remove the last item, only call if count() != 0 | 260 * Remove the last item, only call if count() != 0 |
| 261 */ | 261 */ |
| 262 void pop_back() { | 262 void pop_back() { |
| 263 this->back().~T(); | 263 this->back().~T(); |
| 264 fAllocator.pop_back(); | 264 fAllocator.pop_back(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 public: | 371 public: |
| 372 GrSTAllocator() : INHERITED(N) { | 372 GrSTAllocator() : INHERITED(N) { |
| 373 this->setInitialBlock(fStorage.get()); | 373 this->setInitialBlock(fStorage.get()); |
| 374 } | 374 } |
| 375 | 375 |
| 376 private: | 376 private: |
| 377 SkAlignedSTStorage<N, T> fStorage; | 377 SkAlignedSTStorage<N, T> fStorage; |
| 378 }; | 378 }; |
| 379 | 379 |
| 380 #endif | 380 #endif |
| OLD | NEW |