Cap SkVarAlloc's desired block at 64K.

This means we can store fLgMinSize in 4 bits (TBD).

Local perf comparison calls this harmless-to-slightly-helpful.  Nothing to get
excited about, but seems to certainly not harm perf.

BUG=skia:

Review URL: https://codereview.chromium.org/722293003
This commit is contained in:
mtklein 2014-11-13 13:55:22 -08:00 committed by Commit bot
parent 6740feb093
commit 975ae5e4b8
2 changed files with 12 additions and 3 deletions

View File

@ -7,6 +7,11 @@
#include <malloc.h>
#endif
enum {
kMinLgSize = 4, // The smallest block we'd ever want to allocate is 16B,
kMaxLgSize = 16, // and we see no benefit allocating blocks larger than 64K.
};
struct SkVarAlloc::Block {
Block* prev;
char* data() { return (char*)(this + 1); }
@ -22,7 +27,7 @@ struct SkVarAlloc::Block {
SkVarAlloc::SkVarAlloc()
: fByte(NULL)
, fRemaining(0)
, fLgMinSize(4)
, fLgSize(kMinLgSize)
, fBlock(NULL) {}
SkVarAlloc::~SkVarAlloc() {
@ -37,7 +42,7 @@ SkVarAlloc::~SkVarAlloc() {
void SkVarAlloc::makeSpace(size_t bytes, unsigned flags) {
SkASSERT(SkIsAlignPtr(bytes));
size_t alloc = 1<<(fLgMinSize++);
size_t alloc = 1<<fLgSize;
while (alloc < bytes + sizeof(Block)) {
alloc *= 2;
}
@ -45,6 +50,10 @@ void SkVarAlloc::makeSpace(size_t bytes, unsigned flags) {
fByte = fBlock->data();
fRemaining = alloc - sizeof(Block);
if (fLgSize < kMaxLgSize) {
fLgSize++;
}
#if defined(SK_BUILD_FOR_MAC)
SkASSERT(alloc == malloc_good_size(alloc));
#elif defined(SK_BUILD_FOR_LINUX)

View File

@ -28,7 +28,7 @@ private:
char* fByte;
unsigned fRemaining;
unsigned fLgMinSize;
unsigned fLgSize; // This is always in the range [4, 16], so it really only needs 4 bits.
struct Block;
Block* fBlock;