| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 : fAllocator(sizeof(T), itemsPerBlock, NULL) {} | 240 : fAllocator(sizeof(T), itemsPerBlock, NULL) {} |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * Adds an item and returns it. | 243 * Adds an item and returns it. |
| 244 * | 244 * |
| 245 * @return the added item. | 245 * @return the added item. |
| 246 */ | 246 */ |
| 247 T& push_back() { | 247 T& push_back() { |
| 248 void* item = fAllocator.push_back(); | 248 void* item = fAllocator.push_back(); |
| 249 SkASSERT(item); | 249 SkASSERT(item); |
| 250 SkNEW_PLACEMENT(item, T); | 250 new (item) T; |
| 251 return *(T*)item; | 251 return *(T*)item; |
| 252 } | 252 } |
| 253 | 253 |
| 254 T& push_back(const T& t) { | 254 T& push_back(const T& t) { |
| 255 void* item = fAllocator.push_back(); | 255 void* item = fAllocator.push_back(); |
| 256 SkASSERT(item); | 256 SkASSERT(item); |
| 257 SkNEW_PLACEMENT_ARGS(item, T, (t)); | 257 new (item) T(t); |
| 258 return *(T*)item; | 258 return *(T*)item; |
| 259 } | 259 } |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * Remove the last item, only call if count() != 0 | 262 * Remove the last item, only call if count() != 0 |
| 263 */ | 263 */ |
| 264 void pop_back() { | 264 void pop_back() { |
| 265 this->back().~T(); | 265 this->back().~T(); |
| 266 fAllocator.pop_back(); | 266 fAllocator.pop_back(); |
| 267 } | 267 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // to match the op new silences warnings about missing op delete when a construc
tor throws an | 389 // to match the op new silences warnings about missing op delete when a construc
tor throws an |
| 390 // exception. | 390 // exception. |
| 391 template <typename T> void operator delete(void*, GrTAllocator<T>*) { | 391 template <typename T> void operator delete(void*, GrTAllocator<T>*) { |
| 392 SK_CRASH(); | 392 SK_CRASH(); |
| 393 } | 393 } |
| 394 | 394 |
| 395 #define GrNEW_APPEND_TO_ALLOCATOR(allocator_ptr, type_name, args) \ | 395 #define GrNEW_APPEND_TO_ALLOCATOR(allocator_ptr, type_name, args) \ |
| 396 new (allocator_ptr) type_name args | 396 new (allocator_ptr) type_name args |
| 397 | 397 |
| 398 #endif | 398 #endif |
| OLD | NEW |