epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkTDArray_DEFINED |
| 11 | #define SkTDArray_DEFINED |
| 12 | |
| 13 | #include "SkTypes.h" |
| 14 | |
ehsan.akhgari | db5f7bf | 2014-07-09 11:13:55 -0700 | [diff] [blame] | 15 | template <typename T> class SkTDArray { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | public: |
| 17 | SkTDArray() { |
| 18 | fReserve = fCount = 0; |
| 19 | fArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | } |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 21 | SkTDArray(const T src[], int count) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | SkASSERT(src || count == 0); |
| 23 | |
| 24 | fReserve = fCount = 0; |
| 25 | fArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | if (count) { |
| 27 | fArray = (T*)sk_malloc_throw(count * sizeof(T)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | memcpy(fArray, src, sizeof(T) * count); |
| 29 | fReserve = fCount = count; |
| 30 | } |
| 31 | } |
| 32 | SkTDArray(const SkTDArray<T>& src) { |
| 33 | fReserve = fCount = 0; |
| 34 | fArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | SkTDArray<T> tmp(src.fArray, src.fCount); |
| 36 | this->swap(tmp); |
| 37 | } |
| 38 | ~SkTDArray() { |
| 39 | sk_free(fArray); |
| 40 | } |
| 41 | |
| 42 | SkTDArray<T>& operator=(const SkTDArray<T>& src) { |
| 43 | if (this != &src) { |
| 44 | if (src.fCount > fReserve) { |
| 45 | SkTDArray<T> tmp(src.fArray, src.fCount); |
| 46 | this->swap(tmp); |
| 47 | } else { |
mtklein | cc881da | 2015-12-08 11:55:17 -0800 | [diff] [blame] | 48 | sk_careful_memcpy(fArray, src.fArray, sizeof(T) * src.fCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | fCount = src.fCount; |
| 50 | } |
| 51 | } |
| 52 | return *this; |
| 53 | } |
| 54 | |
reed@google.com | b530ef5 | 2011-07-20 19:55:42 +0000 | [diff] [blame] | 55 | friend bool operator==(const SkTDArray<T>& a, const SkTDArray<T>& b) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | return a.fCount == b.fCount && |
| 57 | (a.fCount == 0 || |
| 58 | !memcmp(a.fArray, b.fArray, a.fCount * sizeof(T))); |
| 59 | } |
reed@google.com | 3467ee0 | 2013-05-29 18:05:52 +0000 | [diff] [blame] | 60 | friend bool operator!=(const SkTDArray<T>& a, const SkTDArray<T>& b) { |
| 61 | return !(a == b); |
| 62 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | |
| 64 | void swap(SkTDArray<T>& other) { |
| 65 | SkTSwap(fArray, other.fArray); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | SkTSwap(fReserve, other.fReserve); |
| 67 | SkTSwap(fCount, other.fCount); |
| 68 | } |
| 69 | |
reed@android.com | 0da41db | 2009-08-25 16:03:59 +0000 | [diff] [blame] | 70 | /** Return a ptr to the array of data, to be freed with sk_free. This also |
| 71 | resets the SkTDArray to be empty. |
| 72 | */ |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 73 | T* release() { |
reed@android.com | 0da41db | 2009-08-25 16:03:59 +0000 | [diff] [blame] | 74 | T* array = fArray; |
| 75 | fArray = NULL; |
| 76 | fReserve = fCount = 0; |
reed@android.com | 0da41db | 2009-08-25 16:03:59 +0000 | [diff] [blame] | 77 | return array; |
| 78 | } |
| 79 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | bool isEmpty() const { return fCount == 0; } |
reed@google.com | 1271d78 | 2011-11-28 19:54:12 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Return the number of elements in the array |
| 84 | */ |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 85 | int count() const { return fCount; } |
reed@google.com | 1271d78 | 2011-11-28 19:54:12 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
commit-bot@chromium.org | 046f1f6 | 2014-02-11 10:17:02 +0000 | [diff] [blame] | 88 | * Return the total number of elements allocated. |
| 89 | * reserved() - count() gives you the number of elements you can add |
| 90 | * without causing an allocation. |
| 91 | */ |
| 92 | int reserved() const { return fReserve; } |
| 93 | |
| 94 | /** |
reed@google.com | 1271d78 | 2011-11-28 19:54:12 +0000 | [diff] [blame] | 95 | * return the number of bytes in the array: count * sizeof(T) |
| 96 | */ |
| 97 | size_t bytes() const { return fCount * sizeof(T); } |
| 98 | |
commit-bot@chromium.org | aa537d4 | 2013-02-28 19:03:13 +0000 | [diff] [blame] | 99 | T* begin() { return fArray; } |
| 100 | const T* begin() const { return fArray; } |
| 101 | T* end() { return fArray ? fArray + fCount : NULL; } |
| 102 | const T* end() const { return fArray ? fArray + fCount : NULL; } |
| 103 | |
| 104 | T& operator[](int index) { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 105 | SkASSERT(index < fCount); |
commit-bot@chromium.org | aa537d4 | 2013-02-28 19:03:13 +0000 | [diff] [blame] | 106 | return fArray[index]; |
| 107 | } |
| 108 | const T& operator[](int index) const { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 109 | SkASSERT(index < fCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | return fArray[index]; |
| 111 | } |
skia.committer@gmail.com | 7fc0e0a | 2013-01-15 02:01:40 +0000 | [diff] [blame] | 112 | |
commit-bot@chromium.org | aa537d4 | 2013-02-28 19:03:13 +0000 | [diff] [blame] | 113 | T& getAt(int index) { |
| 114 | return (*this)[index]; |
| 115 | } |
| 116 | const T& getAt(int index) const { |
humper@google.com | 7af56be | 2013-01-14 18:49:19 +0000 | [diff] [blame] | 117 | return (*this)[index]; |
| 118 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | |
| 120 | void reset() { |
| 121 | if (fArray) { |
| 122 | sk_free(fArray); |
| 123 | fArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | fReserve = fCount = 0; |
| 125 | } else { |
| 126 | SkASSERT(fReserve == 0 && fCount == 0); |
| 127 | } |
| 128 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 129 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | void rewind() { |
| 131 | // same as setCount(0) |
| 132 | fCount = 0; |
| 133 | } |
| 134 | |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 135 | /** |
| 136 | * Sets the number of elements in the array. |
| 137 | * If the array does not have space for count elements, it will increase |
| 138 | * the storage allocated to some amount greater than that required. |
robertphillips | 91df6c2 | 2015-04-24 11:10:51 -0700 | [diff] [blame] | 139 | * It will never shrink the storage. |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 140 | */ |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 141 | void setCount(int count) { |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 142 | SkASSERT(count >= 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | if (count > fReserve) { |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 144 | this->resizeStorageToAtLeast(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | } |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 146 | fCount = count; |
| 147 | } |
| 148 | |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 149 | void setReserve(int reserve) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | if (reserve > fReserve) { |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 151 | this->resizeStorageToAtLeast(reserve); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | T* prepend() { |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 156 | this->adjustCount(1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | memmove(fArray + 1, fArray, (fCount - 1) * sizeof(T)); |
| 158 | return fArray; |
| 159 | } |
| 160 | |
| 161 | T* append() { |
| 162 | return this->append(1, NULL); |
| 163 | } |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 164 | T* append(int count, const T* src = NULL) { |
| 165 | int oldCount = fCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | if (count) { |
| 167 | SkASSERT(src == NULL || fArray == NULL || |
| 168 | src + count <= fArray || fArray + oldCount <= src); |
| 169 | |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 170 | this->adjustCount(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 171 | if (src) { |
| 172 | memcpy(fArray + oldCount, src, sizeof(T) * count); |
| 173 | } |
| 174 | } |
| 175 | return fArray + oldCount; |
| 176 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 177 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 178 | T* appendClear() { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 179 | T* result = this->append(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | *result = 0; |
| 181 | return result; |
| 182 | } |
| 183 | |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 184 | T* insert(int index) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | return this->insert(index, 1, NULL); |
| 186 | } |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 187 | T* insert(int index, int count, const T* src = NULL) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 188 | SkASSERT(count); |
| 189 | SkASSERT(index <= fCount); |
tomhudson@google.com | ffe39bd | 2012-05-17 15:38:00 +0000 | [diff] [blame] | 190 | size_t oldCount = fCount; |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 191 | this->adjustCount(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | T* dst = fArray + index; |
| 193 | memmove(dst + count, dst, sizeof(T) * (oldCount - index)); |
| 194 | if (src) { |
| 195 | memcpy(dst, src, sizeof(T) * count); |
| 196 | } |
| 197 | return dst; |
| 198 | } |
| 199 | |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 200 | void remove(int index, int count = 1) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 201 | SkASSERT(index + count <= fCount); |
| 202 | fCount = fCount - count; |
| 203 | memmove(fArray + index, fArray + index + count, sizeof(T) * (fCount - index)); |
| 204 | } |
| 205 | |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 206 | void removeShuffle(int index) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 207 | SkASSERT(index < fCount); |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 208 | int newCount = fCount - 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 209 | fCount = newCount; |
| 210 | if (index != newCount) { |
| 211 | memcpy(fArray + index, fArray + newCount, sizeof(T)); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | int find(const T& elem) const { |
| 216 | const T* iter = fArray; |
| 217 | const T* stop = fArray + fCount; |
| 218 | |
| 219 | for (; iter < stop; iter++) { |
| 220 | if (*iter == elem) { |
fmalita | f89f60f | 2015-02-13 08:55:24 -0800 | [diff] [blame] | 221 | return SkToInt(iter - fArray); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | return -1; |
| 225 | } |
| 226 | |
| 227 | int rfind(const T& elem) const { |
| 228 | const T* iter = fArray + fCount; |
| 229 | const T* stop = fArray; |
| 230 | |
| 231 | while (iter > stop) { |
| 232 | if (*--iter == elem) { |
reed@google.com | 6fcd28b | 2014-02-04 16:03:51 +0000 | [diff] [blame] | 233 | return SkToInt(iter - stop); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | return -1; |
| 237 | } |
| 238 | |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 239 | /** |
epoger@google.com | af07d06 | 2012-07-13 14:53:18 +0000 | [diff] [blame] | 240 | * Returns true iff the array contains this element. |
| 241 | */ |
| 242 | bool contains(const T& elem) const { |
| 243 | return (this->find(elem) >= 0); |
| 244 | } |
| 245 | |
| 246 | /** |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 247 | * Copies up to max elements into dst. The number of items copied is |
| 248 | * capped by count - index. The actual number copied is returned. |
| 249 | */ |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 250 | int copyRange(T* dst, int index, int max) const { |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 251 | SkASSERT(max >= 0); |
| 252 | SkASSERT(!max || dst); |
| 253 | if (index >= fCount) { |
| 254 | return 0; |
| 255 | } |
| 256 | int count = SkMin32(max, fCount - index); |
| 257 | memcpy(dst, fArray + index, sizeof(T) * count); |
| 258 | return count; |
| 259 | } |
| 260 | |
| 261 | void copy(T* dst) const { |
zachr@google.com | c6081ab | 2013-07-01 17:04:32 +0000 | [diff] [blame] | 262 | this->copyRange(dst, 0, fCount); |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 263 | } |
| 264 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 265 | // routines to treat the array like a stack |
mtklein | aa90d00 | 2014-09-11 06:36:11 -0700 | [diff] [blame] | 266 | T* push() { return this->append(); } |
| 267 | void push(const T& elem) { *this->append() = elem; } |
| 268 | const T& top() const { return (*this)[fCount - 1]; } |
| 269 | T& top() { return (*this)[fCount - 1]; } |
| 270 | void pop(T* elem) { SkASSERT(fCount > 0); if (elem) *elem = (*this)[fCount - 1]; --fCount; } |
| 271 | void pop() { SkASSERT(fCount > 0); --fCount; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 272 | |
| 273 | void deleteAll() { |
| 274 | T* iter = fArray; |
| 275 | T* stop = fArray + fCount; |
| 276 | while (iter < stop) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 277 | delete *iter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 278 | iter += 1; |
| 279 | } |
| 280 | this->reset(); |
| 281 | } |
| 282 | |
| 283 | void freeAll() { |
| 284 | T* iter = fArray; |
| 285 | T* stop = fArray + fCount; |
| 286 | while (iter < stop) { |
| 287 | sk_free(*iter); |
| 288 | iter += 1; |
| 289 | } |
| 290 | this->reset(); |
| 291 | } |
| 292 | |
| 293 | void unrefAll() { |
| 294 | T* iter = fArray; |
| 295 | T* stop = fArray + fCount; |
| 296 | while (iter < stop) { |
| 297 | (*iter)->unref(); |
| 298 | iter += 1; |
| 299 | } |
| 300 | this->reset(); |
| 301 | } |
reed@android.com | 8433b5d | 2009-07-03 02:52:27 +0000 | [diff] [blame] | 302 | |
| 303 | void safeUnrefAll() { |
| 304 | T* iter = fArray; |
| 305 | T* stop = fArray + fCount; |
| 306 | while (iter < stop) { |
| 307 | SkSafeUnref(*iter); |
| 308 | iter += 1; |
| 309 | } |
| 310 | this->reset(); |
| 311 | } |
| 312 | |
commit-bot@chromium.org | aa537d4 | 2013-02-28 19:03:13 +0000 | [diff] [blame] | 313 | void visitAll(void visitor(T&)) { |
bsalomon@google.com | 21cbec4 | 2013-01-07 17:23:00 +0000 | [diff] [blame] | 314 | T* stop = this->end(); |
| 315 | for (T* curr = this->begin(); curr < stop; curr++) { |
| 316 | if (*curr) { |
| 317 | visitor(*curr); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | #ifdef SK_DEBUG |
| 323 | void validate() const { |
| 324 | SkASSERT((fReserve == 0 && fArray == NULL) || |
| 325 | (fReserve > 0 && fArray != NULL)); |
| 326 | SkASSERT(fCount <= fReserve); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 327 | } |
| 328 | #endif |
| 329 | |
mtklein | 092dab9 | 2014-10-09 18:22:41 -0700 | [diff] [blame] | 330 | void shrinkToFit() { |
| 331 | fReserve = fCount; |
| 332 | fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T)); |
| 333 | } |
| 334 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 336 | T* fArray; |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 337 | int fReserve; |
| 338 | int fCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 339 | |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 340 | /** |
| 341 | * Adjusts the number of elements in the array. |
| 342 | * This is the same as calling setCount(count() + delta). |
| 343 | */ |
| 344 | void adjustCount(int delta) { |
| 345 | this->setCount(fCount + delta); |
| 346 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 347 | |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 348 | /** |
commit-bot@chromium.org | a87b21c | 2014-02-11 18:22:04 +0000 | [diff] [blame] | 349 | * Increase the storage allocation such that it can hold (fCount + extra) |
| 350 | * elements. |
| 351 | * It never shrinks the allocation, and it may increase the allocation by |
| 352 | * more than is strictly required, based on a private growth heuristic. |
| 353 | * |
| 354 | * note: does NOT modify fCount |
| 355 | */ |
| 356 | void resizeStorageToAtLeast(int count) { |
| 357 | SkASSERT(count > fReserve); |
commit-bot@chromium.org | ca21a00 | 2014-02-13 18:35:54 +0000 | [diff] [blame] | 358 | fReserve = count + 4; |
| 359 | fReserve += fReserve / 4; |
| 360 | fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 361 | } |
| 362 | }; |
| 363 | |
| 364 | #endif |