Chromium Code Reviews| 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_DEFINED | 10 #ifndef SkTDArray_DEFINED |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 | 210 |
| 211 void removeShuffle(int index) { | 211 void removeShuffle(int index) { |
| 212 SkASSERT(index < fCount); | 212 SkASSERT(index < fCount); |
| 213 int newCount = fCount - 1; | 213 int newCount = fCount - 1; |
| 214 fCount = newCount; | 214 fCount = newCount; |
| 215 if (index != newCount) { | 215 if (index != newCount) { |
| 216 memcpy(fArray + index, fArray + newCount, sizeof(T)); | 216 memcpy(fArray + index, fArray + newCount, sizeof(T)); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 template <typename S> int select(S&& selector) const { | |
|
herb_g
2016/08/29 14:39:50
Select in many other languages usually returns ALL
| |
| 221 const T* iter = fArray; | |
| 222 const T* stop = fArray + fCount; | |
| 223 | |
| 224 for (; iter < stop; iter++) { | |
| 225 if (selector(*iter)) { | |
| 226 return SkToInt(iter - fArray); | |
| 227 } | |
| 228 } | |
| 229 return -1; | |
|
herb_g
2016/08/29 14:39:50
I agree with Mike. I think that count is a better
| |
| 230 } | |
| 231 | |
| 220 int find(const T& elem) const { | 232 int find(const T& elem) const { |
| 221 const T* iter = fArray; | 233 const T* iter = fArray; |
| 222 const T* stop = fArray + fCount; | 234 const T* stop = fArray + fCount; |
| 223 | 235 |
| 224 for (; iter < stop; iter++) { | 236 for (; iter < stop; iter++) { |
| 225 if (*iter == elem) { | 237 if (*iter == elem) { |
| 226 return SkToInt(iter - fArray); | 238 return SkToInt(iter - fArray); |
| 227 } | 239 } |
| 228 } | 240 } |
| 229 return -1; | 241 return -1; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 */ | 372 */ |
| 361 void resizeStorageToAtLeast(int count) { | 373 void resizeStorageToAtLeast(int count) { |
| 362 SkASSERT(count > fReserve); | 374 SkASSERT(count > fReserve); |
| 363 fReserve = count + 4; | 375 fReserve = count + 4; |
| 364 fReserve += fReserve / 4; | 376 fReserve += fReserve / 4; |
| 365 fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T)); | 377 fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T)); |
| 366 } | 378 } |
| 367 }; | 379 }; |
| 368 | 380 |
| 369 #endif | 381 #endif |
| OLD | NEW |