| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 #include "SkChunkAlloc.h" | 8 #include "SkChunkAlloc.h" |
| 9 | 9 |
| 10 // Don't malloc any chunks smaller than this | 10 // Don't malloc any chunks smaller than this |
| 11 #define MIN_CHUNKALLOC_BLOCK_SIZE 1024 | 11 #define MIN_CHUNKALLOC_BLOCK_SIZE 1024 |
| 12 | 12 |
| 13 // Return the new min blocksize given the current value | 13 // Return the new min blocksize given the current value |
| 14 static size_t increase_next_size(size_t size) { | 14 static size_t increase_next_size(size_t size) { |
| 15 return size + (size >> 1); | 15 return size + (size >> 1); |
| 16 } | 16 } |
| 17 | 17 |
| 18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
| 20 struct SkChunkAlloc::Block { | 20 struct SkChunkAlloc::Block { |
| 21 Block* fNext; | 21 Block* fNext; |
| 22 size_t fFreeSize; | 22 size_t fFreeSize; |
| 23 char* fFreePtr; | 23 char* fFreePtr; |
| 24 // data[] follows | 24 // data[] follows |
| 25 | 25 |
| 26 size_t blockSize() { | 26 size_t blockSize() { |
| 27 char* start = this->startOfData(); | 27 char* start = this->startOfData(); |
| 28 size_t bytes = fFreePtr - start; | 28 size_t bytes = fFreePtr - start; |
| 29 return fFreeSize + bytes; | 29 return fFreeSize + bytes; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void reset() { | 32 void reset() { |
| 33 fNext = nullptr; | 33 fNext = nullptr; |
| 34 fFreeSize = this->blockSize(); | 34 fFreeSize = this->blockSize(); |
| 35 fFreePtr = this->startOfData(); | 35 fFreePtr = this->startOfData(); |
| 36 } | 36 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 SkASSERT(fBlockCount == numBlocks); | 228 SkASSERT(fBlockCount == numBlocks); |
| 229 SkASSERT(fTotalCapacity == totCapacity); | 229 SkASSERT(fTotalCapacity == totCapacity); |
| 230 SkASSERT(fTotalUsed == totUsed); | 230 SkASSERT(fTotalUsed == totUsed); |
| 231 SkASSERT(fTotalLost == totLost); | 231 SkASSERT(fTotalLost == totLost); |
| 232 SkASSERT(totCapacity == totUsed + totLost + totAvailable); | 232 SkASSERT(totCapacity == totUsed + totLost + totAvailable); |
| 233 } | 233 } |
| 234 #endif | 234 #endif |
| 235 | |
| OLD | NEW |