Decrease SkClipStack memory allocations & deallocations
http://codereview.appspot.com/6443138
git-svn-id: http://skia.googlecode.com/svn/trunk@5151 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp
index add46e4..e8ff6e8 100644
--- a/src/core/SkClipStack.cpp
+++ b/src/core/SkClipStack.cpp
@@ -439,18 +439,24 @@
}
};
+// This constant determines how many Rec's are allocated together as a block in
+// the deque. As such it needs to balance allocating too much memory vs.
+// incurring allocation/deallocation thrashing. It should roughly correspond to
+// the deepest save/restore stack we expect to see.
+static const int kDefaultRecordAllocCnt = 8;
SkClipStack::SkClipStack()
- : fDeque(sizeof(Rec))
+ : fDeque(sizeof(Rec), kDefaultRecordAllocCnt)
, fSaveCount(0) {
}
-SkClipStack::SkClipStack(const SkClipStack& b) : fDeque(sizeof(Rec)) {
+SkClipStack::SkClipStack(const SkClipStack& b)
+ : fDeque(sizeof(Rec), kDefaultRecordAllocCnt) {
*this = b;
}
SkClipStack::SkClipStack(const SkRect& r)
- : fDeque(sizeof(Rec))
+ : fDeque(sizeof(Rec), kDefaultRecordAllocCnt)
, fSaveCount(0) {
if (!r.isEmpty()) {
this->clipDevRect(r, SkRegion::kReplace_Op, false);
@@ -458,7 +464,7 @@
}
SkClipStack::SkClipStack(const SkIRect& r)
- : fDeque(sizeof(Rec))
+ : fDeque(sizeof(Rec), kDefaultRecordAllocCnt)
, fSaveCount(0) {
if (!r.isEmpty()) {
SkRect temp;