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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } else { | 144 } else { |
| 145 SkASSERT(fReserve == 0 && fCount == 0); | 145 SkASSERT(fReserve == 0 && fCount == 0); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void rewind() { | 149 void rewind() { |
| 150 // same as setCount(0) | 150 // same as setCount(0) |
| 151 fCount = 0; | 151 fCount = 0; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void setCount(int count) { | 154 void setCount(int count) { |
|
reed1
2014/02/07 15:37:49
yikes -- what can this API mean if it doesn't chan
iancottrell
2014/02/07 16:54:15
Done.
| |
| 155 if (count > fReserve) { | 155 if (count > fReserve) { |
| 156 this->growBy(count - fCount); | 156 this->growBy(count - fCount); |
| 157 } else { | 157 } else { |
| 158 fCount = count; | 158 fCount = count; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 void setCountExact(int count) { | |
| 163 if (count > fReserve) { | |
| 164 this->growTo(count); | |
| 165 } | |
| 166 fCount = count; | |
| 167 } | |
| 168 | |
| 162 void setReserve(int reserve) { | 169 void setReserve(int reserve) { |
| 163 if (reserve > fReserve) { | 170 if (reserve > fReserve) { |
| 164 SkASSERT(reserve > fCount); | 171 SkASSERT(reserve > fCount); |
| 165 int count = fCount; | 172 int count = fCount; |
| 166 this->growBy(reserve - fCount); | 173 this->growBy(reserve - fCount); |
| 167 fCount = count; | 174 fCount = count; |
| 168 } | 175 } |
| 169 } | 176 } |
| 170 | 177 |
| 171 T* prepend() { | 178 T* prepend() { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 enum { | 356 enum { |
| 350 kDebugArraySize = 16 | 357 kDebugArraySize = 16 |
| 351 }; | 358 }; |
| 352 typedef T ArrayT[kDebugArraySize]; | 359 typedef T ArrayT[kDebugArraySize]; |
| 353 ArrayT* fData; | 360 ArrayT* fData; |
| 354 #endif | 361 #endif |
| 355 T* fArray; | 362 T* fArray; |
| 356 int fReserve; | 363 int fReserve; |
| 357 int fCount; | 364 int fCount; |
| 358 | 365 |
| 366 void growTo(int size) { | |
|
reed1
2014/02/07 15:37:49
/**
* This resizes the storage to *exactly* size
iancottrell
2014/02/07 16:54:15
Done.
| |
| 367 fArray = (T*)sk_realloc_throw(fArray, size * sizeof(T)); | |
| 368 #ifdef SK_DEBUG | |
| 369 fData = (ArrayT*)fArray; | |
| 370 #endif | |
| 371 fReserve = size; | |
| 372 } | |
| 373 | |
| 359 void growBy(int extra) { | 374 void growBy(int extra) { |
|
reed1
2014/02/07 15:37:49
/**
* Increase the storage allocation such it can
iancottrell
2014/02/07 16:54:15
Done.
| |
| 360 SkASSERT(extra); | 375 SkASSERT(extra); |
| 361 | 376 |
| 362 if (fCount + extra > fReserve) { | 377 if (fCount + extra > fReserve) { |
| 363 int size = fCount + extra + 4; | 378 int size = fCount + extra + 4; |
| 364 size += size >> 2; | 379 growTo(size + (size >> 2)); |
| 365 | |
| 366 fArray = (T*)sk_realloc_throw(fArray, size * sizeof(T)); | |
| 367 #ifdef SK_DEBUG | |
| 368 fData = (ArrayT*)fArray; | |
| 369 #endif | |
| 370 fReserve = size; | |
| 371 } | 380 } |
| 372 fCount += extra; | 381 fCount += extra; |
| 373 } | 382 } |
| 374 }; | 383 }; |
| 375 | 384 |
| 376 #endif | 385 #endif |
| OLD | NEW |