Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: src/core/SkVarAlloc.cpp

Issue 722293003: Cap SkVarAlloc's desired block at 64K. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkVarAlloc.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkVarAlloc.cpp
diff --git a/src/core/SkVarAlloc.cpp b/src/core/SkVarAlloc.cpp
index cc1fc1c734113072e9d57f93e75b8c110a626d81..6f5b5a18d3a16427a9d6c7b49bfb1bbfa1f53b24 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)
« no previous file with comments | « src/core/SkVarAlloc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698