Silence clang-tidy warnings around SkBlockAllocator

Change-Id: I4a825c0d191f3f24d558c4331e07fe2a55832f76
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441838
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Michael Ludwig 2021-08-25 12:26:17 -04:00
parent 3e87a8eda9
commit a228a48d5e
2 changed files with 9 additions and 8 deletions

View File

@ -194,8 +194,8 @@ void SkBlockAllocator::resetScratchSpace() {
} }
} }
void SkBlockAllocator::addBlock(int minimumSize, int maxSize) { void SkBlockAllocator::addBlock(int minSize, int maxSize) {
SkASSERT(minimumSize > (int) sizeof(Block) && minimumSize <= maxSize); SkASSERT(minSize > (int) sizeof(Block) && minSize <= maxSize);
// Max positive value for uint:23 storage (decltype(fN0) picks up uint64_t, not uint:23). // Max positive value for uint:23 storage (decltype(fN0) picks up uint64_t, not uint:23).
static constexpr int kMaxN = (1 << 23) - 1; static constexpr int kMaxN = (1 << 23) - 1;
@ -211,13 +211,13 @@ void SkBlockAllocator::addBlock(int minimumSize, int maxSize) {
int allocSize; int allocSize;
void* mem = nullptr; void* mem = nullptr;
if (this->scratchBlockSize() >= minimumSize) { if (this->scratchBlockSize() >= minSize) {
// Activate the scratch block instead of making a new block // Activate the scratch block instead of making a new block
SkASSERT(fHead.fPrev->isScratch()); SkASSERT(fHead.fPrev->isScratch());
allocSize = fHead.fPrev->fSize; allocSize = fHead.fPrev->fSize;
mem = fHead.fPrev; mem = fHead.fPrev;
fHead.fPrev = nullptr; fHead.fPrev = nullptr;
} else if (minimumSize < maxSize) { } else if (minSize < maxSize) {
// Calculate the 'next' size per growth policy sequence // Calculate the 'next' size per growth policy sequence
GrowthPolicy gp = static_cast<GrowthPolicy>(fGrowthPolicy); GrowthPolicy gp = static_cast<GrowthPolicy>(fGrowthPolicy);
int nextN1 = fN0 + fN1; int nextN1 = fN0 + fN1;
@ -241,13 +241,13 @@ void SkBlockAllocator::addBlock(int minimumSize, int maxSize) {
// maxSize will be sufficient for the requested minimumSize // maxSize will be sufficient for the requested minimumSize
allocSize = maxSize; allocSize = maxSize;
} else { } else {
allocSize = std::min(alignAllocSize(std::max(minimumSize, sizeIncrement * nextN1)), allocSize = std::min(alignAllocSize(std::max(minSize, sizeIncrement * nextN1)),
maxSize); maxSize);
} }
} else { } else {
SkASSERT(minimumSize == maxSize); SkASSERT(minSize == maxSize);
// Still align on a nice boundary, no max clamping since that would just undo the alignment // Still align on a nice boundary, no max clamping since that would just undo the alignment
allocSize = alignAllocSize(minimumSize); allocSize = alignAllocSize(minSize);
} }
// Create new block and append to the linked list of blocks in this allocator // Create new block and append to the linked list of blocks in this allocator
@ -284,7 +284,7 @@ void SkBlockAllocator::validate() const {
prev = block; prev = block;
} }
SkASSERT(prev == fTail); SkASSERT(prev == fTail);
SkASSERT(blocks.size() > 0); SkASSERT(!blocks.empty());
SkASSERT(blocks[0] == &fHead); SkASSERT(blocks[0] == &fHead);
// Confirm reverse iteration matches forward iteration // Confirm reverse iteration matches forward iteration

View File

@ -270,6 +270,7 @@ DEF_TEST(SkBlockAllocatorRewind, r) {
SkDEBUGCODE(pool->validate();) SkDEBUGCODE(pool->validate();)
std::vector<SkBlockAllocator::ByteRange> ptrs; std::vector<SkBlockAllocator::ByteRange> ptrs;
ptrs.reserve(32); // silence clang-tidy performance warning
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ptrs.push_back(pool->allocate<4>(16)); ptrs.push_back(pool->allocate<4>(16));
} }