From 94cbbba96f1a2a425663e631c09591023f2e48d7 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Thu, 9 Mar 2017 16:39:41 -0500 Subject: [PATCH] prealloc room for some number of Elements to avoid malloc I chose 16, as in my test case from android, the depth was at least 9. Possibly we could make it even smaller if our underlying impl (SkDeque) would never prune its allocations, so that we don't malloc repeatedly if we save/restore/save/restore across the boundary of the first/nth chunk... BUG=skia: Change-Id: Id3f0b900b1931f713f80a664f2b4b142f264be8d Reviewed-on: https://skia-review.googlesource.com/9522 Reviewed-by: Brian Salomon Commit-Queue: Mike Reed --- src/core/SkClipStack.cpp | 5 +++-- src/core/SkClipStack.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp index f41945e..d94bdcb 100644 --- a/src/core/SkClipStack.cpp +++ b/src/core/SkClipStack.cpp @@ -495,12 +495,13 @@ void SkClipStack::Element::updateBoundAndGenID(const Element* prior) { static const int kDefaultElementAllocCnt = 8; SkClipStack::SkClipStack() - : fDeque(sizeof(Element), kDefaultElementAllocCnt) + : fDeque(sizeof(Element), fStorage, sizeof(fStorage), kDefaultElementAllocCnt) , fSaveCount(0) { } SkClipStack::SkClipStack(const SkClipStack& b) - : fDeque(sizeof(Element), kDefaultElementAllocCnt) { + : fDeque(sizeof(Element), fStorage, sizeof(fStorage), kDefaultElementAllocCnt) +{ *this = b; } diff --git a/src/core/SkClipStack.h b/src/core/SkClipStack.h index 080712d..fac739e 100644 --- a/src/core/SkClipStack.h +++ b/src/core/SkClipStack.h @@ -522,6 +522,10 @@ public: private: friend class Iter; + enum { + kPreallocCount = 16 + }; + intptr_t fStorage[kPreallocCount * sizeof(Element) / sizeof(intptr_t)]; SkDeque fDeque; int fSaveCount; -- 2.7.4