aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-17 13:53:05 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-17 13:53:05 +0000
commit63ae1cfb10d0d14722df59cba0012f8a4370c090 (patch)
treea07217b4a1b4df64d8c54228882ee876173837ed /include/core
parent1b3ce47c7b6c14c84d7aaee249b33f9d3b473050 (diff)
Make SkDeque::back faster & inline
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkDeque.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/include/core/SkDeque.h b/include/core/SkDeque.h
index 3bf0bdd89d..d29f72a959 100644
--- a/include/core/SkDeque.h
+++ b/include/core/SkDeque.h
@@ -12,6 +12,17 @@
#include "SkTypes.h"
+/*
+ * The deque class works by blindly creating memory space of a specified element
+ * size. It manages the memory as a doubly linked list of blocks each of which
+ * can contain multiple elements. Pushes and pops add/remove blocks from the
+ * beginning/end of the list as necessary while each block tracks the used
+ * portion of its memory.
+ * One behavior to be aware of is that the pops do not immediately remove an
+ * empty block from the beginning/end of the list (Presumably so push/pop pairs
+ * on the block boundaries don't cause thrashing). This can result in the first/
+ * last element not residing in the first/last block.
+ */
class SK_API SkDeque : SkNoncopyable {
public:
/**
@@ -26,8 +37,8 @@ public:
int count() const { return fCount; }
size_t elemSize() const { return fElemSize; }
- const void* front() const;
- const void* back() const;
+ const void* front() const { return fFront; }
+ const void* back() const { return fBack; }
void* front() {
return (void*)((const SkDeque*)this)->front();
@@ -37,6 +48,10 @@ public:
return (void*)((const SkDeque*)this)->back();
}
+ /**
+ * push_front and push_back return a pointer to the memory space
+ * for the new element
+ */
void* push_front();
void* push_back();
@@ -100,8 +115,11 @@ private:
// allow unit test to call numBlocksAllocated
friend class DequeUnitTestHelper;
- Block* fFront;
- Block* fBack;
+ void* fFront;
+ void* fBack;
+
+ Block* fFrontBlock;
+ Block* fBackBlock;
size_t fElemSize;
void* fInitialStorage;
int fCount; // number of elements in the deque