| 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 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 void init(const T* array, int count, | 377 void init(const T* array, int count, |
| 378 void* preAllocStorage, int preAllocOrReserveCount) { | 378 void* preAllocStorage, int preAllocOrReserveCount) { |
| 379 SkASSERT(count >= 0); | 379 SkASSERT(count >= 0); |
| 380 SkASSERT(preAllocOrReserveCount >= 0); | 380 SkASSERT(preAllocOrReserveCount >= 0); |
| 381 fCount = count; | 381 fCount = count; |
| 382 fReserveCount = (preAllocOrReserveCount > 0) ? | 382 fReserveCount = (preAllocOrReserveCount > 0) ? |
| 383 preAllocOrReserveCount : | 383 preAllocOrReserveCount : |
| 384 gMIN_ALLOC_COUNT; | 384 gMIN_ALLOC_COUNT; |
| 385 fPreAllocMemArray = preAllocStorage; | 385 fPreAllocMemArray = preAllocStorage; |
| 386 if (fReserveCount >= fCount && | 386 if (fReserveCount >= fCount && |
| 387 NULL != preAllocStorage) { | 387 preAllocStorage) { |
| 388 fAllocCount = fReserveCount; | 388 fAllocCount = fReserveCount; |
| 389 fMemArray = preAllocStorage; | 389 fMemArray = preAllocStorage; |
| 390 } else { | 390 } else { |
| 391 fAllocCount = SkMax32(fCount, fReserveCount); | 391 fAllocCount = SkMax32(fCount, fReserveCount); |
| 392 fMemArray = sk_malloc_throw(fAllocCount * sizeof(T)); | 392 fMemArray = sk_malloc_throw(fAllocCount * sizeof(T)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 SkTArrayExt::copy(this, array); | 395 SkTArrayExt::copy(this, array); |
| 396 } | 396 } |
| 397 | 397 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 420 if (newCount > fAllocCount || newCount < (fAllocCount / 3)) { | 420 if (newCount > fAllocCount || newCount < (fAllocCount / 3)) { |
| 421 // whether we're growing or shrinking, we leave at least 50% extra s
pace for future | 421 // whether we're growing or shrinking, we leave at least 50% extra s
pace for future |
| 422 // growth (clamped to the reserve count). | 422 // growth (clamped to the reserve count). |
| 423 newAllocCount = SkMax32(newCount + ((newCount + 1) >> 1), fReserveCo
unt); | 423 newAllocCount = SkMax32(newCount + ((newCount + 1) >> 1), fReserveCo
unt); |
| 424 } | 424 } |
| 425 if (newAllocCount != fAllocCount) { | 425 if (newAllocCount != fAllocCount) { |
| 426 | 426 |
| 427 fAllocCount = newAllocCount; | 427 fAllocCount = newAllocCount; |
| 428 char* newMemArray; | 428 char* newMemArray; |
| 429 | 429 |
| 430 if (fAllocCount == fReserveCount && NULL != fPreAllocMemArray) { | 430 if (fAllocCount == fReserveCount && fPreAllocMemArray) { |
| 431 newMemArray = (char*) fPreAllocMemArray; | 431 newMemArray = (char*) fPreAllocMemArray; |
| 432 } else { | 432 } else { |
| 433 newMemArray = (char*) sk_malloc_throw(fAllocCount*sizeof(T)); | 433 newMemArray = (char*) sk_malloc_throw(fAllocCount*sizeof(T)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 SkTArrayExt::copyAndDelete<T>(this, newMemArray); | 436 SkTArrayExt::copyAndDelete<T>(this, newMemArray); |
| 437 | 437 |
| 438 if (fMemArray != fPreAllocMemArray) { | 438 if (fMemArray != fPreAllocMemArray) { |
| 439 sk_free(fMemArray); | 439 sk_free(fMemArray); |
| 440 } | 440 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 SkSTArray& operator= (const INHERITED& array) { | 520 SkSTArray& operator= (const INHERITED& array) { |
| 521 INHERITED::operator=(array); | 521 INHERITED::operator=(array); |
| 522 return *this; | 522 return *this; |
| 523 } | 523 } |
| 524 | 524 |
| 525 private: | 525 private: |
| 526 SkAlignedSTStorage<N,T> fStorage; | 526 SkAlignedSTStorage<N,T> fStorage; |
| 527 }; | 527 }; |
| 528 | 528 |
| 529 #endif | 529 #endif |
| OLD | NEW |