aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-13 13:55:22 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-13 13:55:22 -0800
commit975ae5e4b881d4df41fd06453a650d6312127c8d (patch)
treecc6ac44f294e04f4b514461c55c6bbd03aba058d /src
parent6740feb0938a193610c9e6bba97ab3930fa87217 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/core/SkVarAlloc.cpp13
-rw-r--r--src/core/SkVarAlloc.h2
2 files changed, 12 insertions, 3 deletions
diff --git a/src/core/SkVarAlloc.cpp b/src/core/SkVarAlloc.cpp
index cc1fc1c734..6f5b5a18d3 100644
--- a/src/core/SkVarAlloc.cpp
+++ b/src/core/SkVarAlloc.cpp
@@ -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)
diff --git a/src/core/SkVarAlloc.h b/src/core/SkVarAlloc.h
index 19b2d75e76..2b5401b7f0 100644
--- a/src/core/SkVarAlloc.h
+++ b/src/core/SkVarAlloc.h
@@ -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;