| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 */ | 427 */ |
| 428 template <typename T> T* SkInPlaceNewCheck(void* storage, size_t size) { | 428 template <typename T> T* SkInPlaceNewCheck(void* storage, size_t size) { |
| 429 return (sizeof(T) <= size) ? new (storage) T : new T; | 429 return (sizeof(T) <= size) ? new (storage) T : new T; |
| 430 } | 430 } |
| 431 | 431 |
| 432 template <typename T, typename A1, typename A2, typename A3> | 432 template <typename T, typename A1, typename A2, typename A3> |
| 433 T* SkInPlaceNewCheck(void* storage, size_t size, const A1& a1, const A2& a2, con
st A3& a3) { | 433 T* SkInPlaceNewCheck(void* storage, size_t size, const A1& a1, const A2& a2, con
st A3& a3) { |
| 434 return (sizeof(T) <= size) ? new (storage) T(a1, a2, a3) : new T(a1, a2, a3)
; | 434 return (sizeof(T) <= size) ? new (storage) T(a1, a2, a3) : new T(a1, a2, a3)
; |
| 435 } | 435 } |
| 436 | 436 |
| 437 template <typename T, typename A1, typename A2, typename A3, typename A4> |
| 438 T* SkInPlaceNewCheck(void* storage, size_t size, |
| 439 const A1& a1, const A2& a2, const A3& a3, const A4& a4) { |
| 440 return (sizeof(T) <= size) ? new (storage) T(a1, a2, a3, a4) : new T(a1, a2,
a3, a4); |
| 441 } |
| 442 |
| 437 /** | 443 /** |
| 438 * Reserves memory that is aligned on double and pointer boundaries. | 444 * Reserves memory that is aligned on double and pointer boundaries. |
| 439 * Hopefully this is sufficient for all practical purposes. | 445 * Hopefully this is sufficient for all practical purposes. |
| 440 */ | 446 */ |
| 441 template <size_t N> class SkAlignedSStorage : SkNoncopyable { | 447 template <size_t N> class SkAlignedSStorage : SkNoncopyable { |
| 442 public: | 448 public: |
| 443 size_t size() const { return N; } | 449 size_t size() const { return N; } |
| 444 void* get() { return fData; } | 450 void* get() { return fData; } |
| 445 const void* get() const { return fData; } | 451 const void* get() const { return fData; } |
| 446 | 452 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 464 * Returns void* because this object does not initialize the | 470 * Returns void* because this object does not initialize the |
| 465 * memory. Use placement new for types that require a cons. | 471 * memory. Use placement new for types that require a cons. |
| 466 */ | 472 */ |
| 467 void* get() { return fStorage.get(); } | 473 void* get() { return fStorage.get(); } |
| 468 const void* get() const { return fStorage.get(); } | 474 const void* get() const { return fStorage.get(); } |
| 469 private: | 475 private: |
| 470 SkAlignedSStorage<sizeof(T)*N> fStorage; | 476 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 471 }; | 477 }; |
| 472 | 478 |
| 473 #endif | 479 #endif |
| OLD | NEW |