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 SkTDArray_Experimental_DEFINED | 10 #ifndef SkTDArray_Experimental_DEFINED |
(...skipping 17 matching lines...) Expand all Loading... |
28 #define SkLongArray(type) SkTDArray<type> | 28 #define SkLongArray(type) SkTDArray<type> |
29 #else | 29 #else |
30 | 30 |
31 class SkDS32Array { | 31 class SkDS32Array { |
32 protected: | 32 protected: |
33 SkDS32Array(); | 33 SkDS32Array(); |
34 SkDS32Array(const SkDS32Array& src); | 34 SkDS32Array(const SkDS32Array& src); |
35 SkDS32Array(const int32_t src[], U16CPU count); | 35 SkDS32Array(const int32_t src[], U16CPU count); |
36 SkDS32Array& operator=(const SkDS32Array& src); | 36 SkDS32Array& operator=(const SkDS32Array& src); |
37 friend int operator==(const SkDS32Array& a, const SkDS32Array& b); | 37 friend int operator==(const SkDS32Array& a, const SkDS32Array& b); |
38 int32_t* append() { return this->append(1, NULL); } | 38 int32_t* append() { return this->append(1, nullptr); } |
39 int32_t* append(U16CPU count, const int32_t* src = NULL); | 39 int32_t* append(U16CPU count, const int32_t* src = nullptr); |
40 | 40 |
41 int32_t* appendClear() | 41 int32_t* appendClear() |
42 { | 42 { |
43 int32_t* result = this->append(); | 43 int32_t* result = this->append(); |
44 *result = 0; | 44 *result = 0; |
45 return result; | 45 return result; |
46 } | 46 } |
47 | 47 |
48 int find(const int32_t& elem) const; | 48 int find(const int32_t& elem) const; |
49 int32_t* insert(U16CPU index, U16CPU count, const int32_t* src); | 49 int32_t* insert(U16CPU index, U16CPU count, const int32_t* src); |
50 int rfind(const int32_t& elem) const; | 50 int rfind(const int32_t& elem) const; |
51 void swap(SkDS32Array& other); | 51 void swap(SkDS32Array& other); |
52 public: | 52 public: |
53 bool isEmpty() const { return fCount == 0; } | 53 bool isEmpty() const { return fCount == 0; } |
54 int count() const { return fCount; } | 54 int count() const { return fCount; } |
55 | 55 |
56 void remove(U16CPU index, U16CPU count = 1) | 56 void remove(U16CPU index, U16CPU count = 1) |
57 { | 57 { |
58 SkASSERT(index + count <= fCount); | 58 SkASSERT(index + count <= fCount); |
59 fCount = SkToU16(fCount - count); | 59 fCount = SkToU16(fCount - count); |
60 memmove(fArray + index, fArray + index + count, sizeof(int32_t) * (fCoun
t - index)); | 60 memmove(fArray + index, fArray + index + count, sizeof(int32_t) * (fCoun
t - index)); |
61 } | 61 } |
62 | 62 |
63 void reset() | 63 void reset() |
64 { | 64 { |
65 if (fArray) | 65 if (fArray) |
66 { | 66 { |
67 sk_free(fArray); | 67 sk_free(fArray); |
68 fArray = NULL; | 68 fArray = nullptr; |
69 #ifdef SK_DEBUG | 69 #ifdef SK_DEBUG |
70 fData = NULL; | 70 fData = nullptr; |
71 #endif | 71 #endif |
72 fReserve = fCount = 0; | 72 fReserve = fCount = 0; |
73 } | 73 } |
74 else | 74 else |
75 { | 75 { |
76 SkASSERT(fReserve == 0 && fCount == 0); | 76 SkASSERT(fReserve == 0 && fCount == 0); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 void setCount(U16CPU count) | 80 void setCount(U16CPU count) |
(...skipping 16 matching lines...) Expand all Loading... |
97 }; | 97 }; |
98 | 98 |
99 #ifdef SK_DEBUG | 99 #ifdef SK_DEBUG |
100 #define SYNC() fTData = (T (*)[kDebugArraySize]) fArray | 100 #define SYNC() fTData = (T (*)[kDebugArraySize]) fArray |
101 #else | 101 #else |
102 #define SYNC() | 102 #define SYNC() |
103 #endif | 103 #endif |
104 | 104 |
105 template <typename T> class SkTDS32Array : public SkDS32Array { | 105 template <typename T> class SkTDS32Array : public SkDS32Array { |
106 public: | 106 public: |
107 SkTDS32Array() { SkDEBUGCODE(fTData=NULL); SkASSERT(sizeof(T) == sizeof(int3
2_t)); } | 107 SkTDS32Array() { SkDEBUGCODE(fTData=nullptr); SkASSERT(sizeof(T) == sizeof(i
nt32_t)); } |
108 SkTDS32Array(const SkTDS32Array<T>& src) : SkDS32Array(src) {} | 108 SkTDS32Array(const SkTDS32Array<T>& src) : SkDS32Array(src) {} |
109 ~SkTDS32Array() { sk_free(fArray); } | 109 ~SkTDS32Array() { sk_free(fArray); } |
110 T& operator[](int index) const { SYNC(); SkASSERT((unsigned)index < fCount)
; return ((T*) fArray)[index]; } | 110 T& operator[](int index) const { SYNC(); SkASSERT((unsigned)index < fCount)
; return ((T*) fArray)[index]; } |
111 SkTDS32Array<T>& operator=(const SkTDS32Array<T>& src) { | 111 SkTDS32Array<T>& operator=(const SkTDS32Array<T>& src) { |
112 return (SkTDS32Array<T>&) SkDS32Array::operator=(src); } | 112 return (SkTDS32Array<T>&) SkDS32Array::operator=(src); } |
113 friend int operator==(const SkTDS32Array<T>& a, const SkTDS32Array<T>& b) { | 113 friend int operator==(const SkTDS32Array<T>& a, const SkTDS32Array<T>& b) { |
114 return operator==((const SkDS32Array&) a, (const SkDS32Array&) b); } | 114 return operator==((const SkDS32Array&) a, (const SkDS32Array&) b); } |
115 T* append() { return (T*) SkDS32Array::append(); } | 115 T* append() { return (T*) SkDS32Array::append(); } |
116 T* appendClear() { return (T*) SkDS32Array::appendClear(); } | 116 T* appendClear() { return (T*) SkDS32Array::appendClear(); } |
117 T* append(U16CPU count, const T* src = NULL) { return (T*) SkDS32Array::appe
nd(count, (const int32_t*) src); } | 117 T* append(U16CPU count, const T* src = nullptr) { return (T*) SkDS32Array::a
ppend(count, (const int32_t*) src); } |
118 T* begin() const { SYNC(); return (T*) fArray; } | 118 T* begin() const { SYNC(); return (T*) fArray; } |
119 T* end() const { return (T*) (fArray ? fArray + fCount : NULL); } | 119 T* end() const { return (T*) (fArray ? fArray + fCount : nullptr); } |
120 int find(const T& elem) const { return SkDS32Array::find((const int32_t&) el
em); } | 120 int find(const T& elem) const { return SkDS32Array::find((const int32_t&) el
em); } |
121 T* insert(U16CPU index) { return this->insert(index, 1, NULL); } | 121 T* insert(U16CPU index) { return this->insert(index, 1, nullptr); } |
122 T* insert(U16CPU index, U16CPU count, const T* src = NULL) { | 122 T* insert(U16CPU index, U16CPU count, const T* src = nullptr) { |
123 return (T*) SkDS32Array::insert(index, count, (const int32_t*) src); } | 123 return (T*) SkDS32Array::insert(index, count, (const int32_t*) src); } |
124 int rfind(const T& elem) const { return SkDS32Array::rfind((const int32_t&)
elem); } | 124 int rfind(const T& elem) const { return SkDS32Array::rfind((const int32_t&)
elem); } |
125 T* push() { return this->append(); } | 125 T* push() { return this->append(); } |
126 void push(T& elem) { *this->append() = elem; } | 126 void push(T& elem) { *this->append() = elem; } |
127 const T& top() const { return (*this)[fCount - 1]; } | 127 const T& top() const { return (*this)[fCount - 1]; } |
128 T& top() { return (*this)[fCount - 1]; } | 128 T& top() { return (*this)[fCount - 1]; } |
129 void pop(T* elem) { if (elem) *elem = (*this)[fCount - 1]; --fCount;
} | 129 void pop(T* elem) { if (elem) *elem = (*this)[fCount - 1]; --fCount;
} |
130 void pop() { --fCount; } | 130 void pop() { --fCount; } |
131 private: | 131 private: |
132 #ifdef SK_DEBUG | 132 #ifdef SK_DEBUG |
133 mutable T(* fTData)[kDebugArraySize]; | 133 mutable T(* fTData)[kDebugArraySize]; |
134 #endif | 134 #endif |
135 }; | 135 }; |
136 | 136 |
137 #define SkIntArray(type) SkTDS32Array<type> // holds 32 bit data types | 137 #define SkIntArray(type) SkTDS32Array<type> // holds 32 bit data types |
138 #define SkLongArray(type) SkTDS32Array<type> | 138 #define SkLongArray(type) SkTDS32Array<type> |
139 | 139 |
140 #endif // SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT | 140 #endif // SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT |
141 | 141 |
142 #endif // SkTDArray_Experimental_DEFINED | 142 #endif // SkTDArray_Experimental_DEFINED |
OLD | NEW |