| 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 |
| 11 #define SkTemplates_DEFINED | 11 #define SkTemplates_DEFINED |
| 12 | 12 |
| 13 #include "SkMath.h" |
| 13 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 14 #include <limits.h> | 15 #include <limits.h> |
| 15 #include <new> | 16 #include <new> |
| 16 | 17 |
| 17 /** \file SkTemplates.h | 18 /** \file SkTemplates.h |
| 18 | 19 |
| 19 This file contains light-weight template classes for type-safe and exception
-safe | 20 This file contains light-weight template classes for type-safe and exception
-safe |
| 20 resource management. | 21 resource management. |
| 21 */ | 22 */ |
| 22 | 23 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 286 } |
| 286 | 287 |
| 287 if (fCount != count) { | 288 if (fCount != count) { |
| 288 if (fCount > N) { | 289 if (fCount > N) { |
| 289 // 'fArray' was allocated last time so free it now | 290 // 'fArray' was allocated last time so free it now |
| 290 SkASSERT((T*) fStorage != fArray); | 291 SkASSERT((T*) fStorage != fArray); |
| 291 sk_free(fArray); | 292 sk_free(fArray); |
| 292 } | 293 } |
| 293 | 294 |
| 294 if (count > N) { | 295 if (count > N) { |
| 295 fArray = (T*) sk_malloc_throw(count * sizeof(T)); | 296 const uint64_t size64 = sk_64_mul(count, sizeof(T)); |
| 297 const size_t size = static_cast<size_t>(size64); |
| 298 if (size != size64) { |
| 299 sk_out_of_memory(); |
| 300 } |
| 301 fArray = (T*) sk_malloc_throw(size); |
| 296 } else if (count > 0) { | 302 } else if (count > 0) { |
| 297 fArray = (T*) fStorage; | 303 fArray = (T*) fStorage; |
| 298 } else { | 304 } else { |
| 299 fArray = NULL; | 305 fArray = NULL; |
| 300 } | 306 } |
| 301 | 307 |
| 302 fCount = count; | 308 fCount = count; |
| 303 } | 309 } |
| 304 | 310 |
| 305 iter = fArray; | 311 iter = fArray; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 /** | 490 /** |
| 485 * Returns void* because this object does not initialize the | 491 * Returns void* because this object does not initialize the |
| 486 * memory. Use placement new for types that require a cons. | 492 * memory. Use placement new for types that require a cons. |
| 487 */ | 493 */ |
| 488 void* get() { return fStorage.get(); } | 494 void* get() { return fStorage.get(); } |
| 489 private: | 495 private: |
| 490 SkAlignedSStorage<sizeof(T)*N> fStorage; | 496 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 491 }; | 497 }; |
| 492 | 498 |
| 493 #endif | 499 #endif |
| OLD | NEW |