Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 SkTArray_DEFINED | 8 #ifndef SkTArray_DEFINED |
| 9 #define SkTArray_DEFINED | 9 #define SkTArray_DEFINED |
| 10 | 10 |
| 11 #include "../private/SkTemplates.h" | 11 #include "../private/SkTemplates.h" |
| 12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 13 | 13 |
| 14 #include <new> | 14 #include <new> |
| 15 | 15 |
| 16 template <typename T, bool MEM_COPY = false> class SkTArray; | 16 template <typename T, bool MEM_COPY = false> class SkTArray; |
| 17 | 17 |
| 18 namespace SkTArrayExt { | 18 namespace SkTArrayExt { |
| 19 | 19 |
| 20 template<typename T> | 20 template<typename T> |
| 21 inline void copy(SkTArray<T, true>* self, int dst, int src) { | 21 inline void copy(SkTArray<T, true>* self, int dst, int src) { |
| 22 memcpy(&self->fItemArray[dst], &self->fItemArray[src], sizeof(T)); | 22 memcpy(&self->fItemArray[dst], &self->fItemArray[src], sizeof(T)); |
| 23 } | 23 } |
| 24 template<typename T> | 24 template<typename T> |
| 25 inline void copy(SkTArray<T, true>* self, const T* array) { | 25 inline void copy(SkTArray<T, true>* self, const T* array) { |
| 26 memcpy(self->fMemArray, array, self->fCount * sizeof(T)); | 26 if (array) { |
| 27 memcpy(self->fMemArray, array, self->fCount * sizeof(T)); | |
| 28 } | |
| 27 } | 29 } |
| 28 template<typename T> | 30 template<typename T> |
| 29 inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) { | 31 inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) { |
|
tomhudson
2015/12/08 16:31:40
Oddly, this doesn't delete anything?
| |
| 30 memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T)); | 32 if (self->fMemArray) { |
| 33 memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T)); | |
| 34 } | |
| 31 } | 35 } |
| 32 | 36 |
| 33 template<typename T> | 37 template<typename T> |
| 34 inline void copy(SkTArray<T, false>* self, int dst, int src) { | 38 inline void copy(SkTArray<T, false>* self, int dst, int src) { |
| 35 new (&self->fItemArray[dst]) T(self->fItemArray[src]); | 39 new (&self->fItemArray[dst]) T(self->fItemArray[src]); |
| 36 } | 40 } |
| 37 template<typename T> | 41 template<typename T> |
| 38 inline void copy(SkTArray<T, false>* self, const T* array) { | 42 inline void copy(SkTArray<T, false>* self, const T* array) { |
| 39 for (int i = 0; i < self->fCount; ++i) { | 43 for (int i = 0; i < self->fCount; ++i) { |
| 40 new (self->fItemArray + i) T(array[i]); | 44 new (self->fItemArray + i) T(array[i]); |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 SkSTArray& operator= (const INHERITED& array) { | 553 SkSTArray& operator= (const INHERITED& array) { |
| 550 INHERITED::operator=(array); | 554 INHERITED::operator=(array); |
| 551 return *this; | 555 return *this; |
| 552 } | 556 } |
| 553 | 557 |
| 554 private: | 558 private: |
| 555 SkAlignedSTStorage<N,T> fStorage; | 559 SkAlignedSTStorage<N,T> fStorage; |
| 556 }; | 560 }; |
| 557 | 561 |
| 558 #endif | 562 #endif |
| OLD | NEW |