OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 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 SkTemplates_DEFINED | 10 #ifndef SkTemplates_DEFINED |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 171 |
172 template <typename T> class SkAutoTDeleteArray : SkNoncopyable { | 172 template <typename T> class SkAutoTDeleteArray : SkNoncopyable { |
173 public: | 173 public: |
174 SkAutoTDeleteArray(T array[]) : fArray(array) {} | 174 SkAutoTDeleteArray(T array[]) : fArray(array) {} |
175 ~SkAutoTDeleteArray() { SkDELETE_ARRAY(fArray); } | 175 ~SkAutoTDeleteArray() { SkDELETE_ARRAY(fArray); } |
176 | 176 |
177 T* get() const { return fArray; } | 177 T* get() const { return fArray; } |
178 void free() { SkDELETE_ARRAY(fArray); fArray = NULL; } | 178 void free() { SkDELETE_ARRAY(fArray); fArray = NULL; } |
179 T* detach() { T* array = fArray; fArray = NULL; return array; } | 179 T* detach() { T* array = fArray; fArray = NULL; return array; } |
180 | 180 |
181 void reset(T array[]) { | |
182 if (fArray != array) { | |
183 SkDELETE_ARRAY(fArray); | |
robertphillips
2014/01/31 00:23:13
Move the assignment outside of the if block?
| |
184 fArray = array; | |
185 } | |
186 } | |
187 | |
181 private: | 188 private: |
182 T* fArray; | 189 T* fArray; |
183 }; | 190 }; |
184 | 191 |
185 /** Allocate an array of T elements, and free the array in the destructor | 192 /** Allocate an array of T elements, and free the array in the destructor |
186 */ | 193 */ |
187 template <typename T> class SkAutoTArray : SkNoncopyable { | 194 template <typename T> class SkAutoTArray : SkNoncopyable { |
188 public: | 195 public: |
189 SkAutoTArray() { | 196 SkAutoTArray() { |
190 fArray = NULL; | 197 fArray = NULL; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 /** | 469 /** |
463 * Returns void* because this object does not initialize the | 470 * Returns void* because this object does not initialize the |
464 * memory. Use placement new for types that require a cons. | 471 * memory. Use placement new for types that require a cons. |
465 */ | 472 */ |
466 void* get() { return fStorage.get(); } | 473 void* get() { return fStorage.get(); } |
467 private: | 474 private: |
468 SkAlignedSStorage<sizeof(T)*N> fStorage; | 475 SkAlignedSStorage<sizeof(T)*N> fStorage; |
469 }; | 476 }; |
470 | 477 |
471 #endif | 478 #endif |
OLD | NEW |