gfx/skia/trunk/include/core/SkDeque.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkDeque_DEFINED
michael@0 11 #define SkDeque_DEFINED
michael@0 12
michael@0 13 #include "SkTypes.h"
michael@0 14
michael@0 15 /*
michael@0 16 * The deque class works by blindly creating memory space of a specified element
michael@0 17 * size. It manages the memory as a doubly linked list of blocks each of which
michael@0 18 * can contain multiple elements. Pushes and pops add/remove blocks from the
michael@0 19 * beginning/end of the list as necessary while each block tracks the used
michael@0 20 * portion of its memory.
michael@0 21 * One behavior to be aware of is that the pops do not immediately remove an
michael@0 22 * empty block from the beginning/end of the list (Presumably so push/pop pairs
michael@0 23 * on the block boundaries don't cause thrashing). This can result in the first/
michael@0 24 * last element not residing in the first/last block.
michael@0 25 */
michael@0 26 class SK_API SkDeque : SkNoncopyable {
michael@0 27 public:
michael@0 28 /**
michael@0 29 * elemSize specifies the size of each individual element in the deque
michael@0 30 * allocCount specifies how many elements are to be allocated as a block
michael@0 31 */
michael@0 32 explicit SkDeque(size_t elemSize, int allocCount = 1);
michael@0 33 SkDeque(size_t elemSize, void* storage, size_t storageSize, int allocCount = 1);
michael@0 34 ~SkDeque();
michael@0 35
michael@0 36 bool empty() const { return 0 == fCount; }
michael@0 37 int count() const { return fCount; }
michael@0 38 size_t elemSize() const { return fElemSize; }
michael@0 39
michael@0 40 const void* front() const { return fFront; }
michael@0 41 const void* back() const { return fBack; }
michael@0 42
michael@0 43 void* front() {
michael@0 44 return (void*)((const SkDeque*)this)->front();
michael@0 45 }
michael@0 46
michael@0 47 void* back() {
michael@0 48 return (void*)((const SkDeque*)this)->back();
michael@0 49 }
michael@0 50
michael@0 51 /**
michael@0 52 * push_front and push_back return a pointer to the memory space
michael@0 53 * for the new element
michael@0 54 */
michael@0 55 void* push_front();
michael@0 56 void* push_back();
michael@0 57
michael@0 58 void pop_front();
michael@0 59 void pop_back();
michael@0 60
michael@0 61 private:
michael@0 62 struct Block;
michael@0 63
michael@0 64 public:
michael@0 65 class Iter {
michael@0 66 public:
michael@0 67 enum IterStart {
michael@0 68 kFront_IterStart,
michael@0 69 kBack_IterStart
michael@0 70 };
michael@0 71
michael@0 72 /**
michael@0 73 * Creates an uninitialized iterator. Must be reset()
michael@0 74 */
michael@0 75 Iter();
michael@0 76
michael@0 77 Iter(const SkDeque& d, IterStart startLoc);
michael@0 78 void* next();
michael@0 79 void* prev();
michael@0 80
michael@0 81 void reset(const SkDeque& d, IterStart startLoc);
michael@0 82
michael@0 83 private:
michael@0 84 SkDeque::Block* fCurBlock;
michael@0 85 char* fPos;
michael@0 86 size_t fElemSize;
michael@0 87 };
michael@0 88
michael@0 89 // Inherit privately from Iter to prevent access to reverse iteration
michael@0 90 class F2BIter : private Iter {
michael@0 91 public:
michael@0 92 F2BIter() {}
michael@0 93
michael@0 94 /**
michael@0 95 * Wrap Iter's 2 parameter ctor to force initialization to the
michael@0 96 * beginning of the deque
michael@0 97 */
michael@0 98 F2BIter(const SkDeque& d) : INHERITED(d, kFront_IterStart) {}
michael@0 99
michael@0 100 using Iter::next;
michael@0 101
michael@0 102 /**
michael@0 103 * Wrap Iter::reset to force initialization to the beginning of the
michael@0 104 * deque
michael@0 105 */
michael@0 106 void reset(const SkDeque& d) {
michael@0 107 this->INHERITED::reset(d, kFront_IterStart);
michael@0 108 }
michael@0 109
michael@0 110 private:
michael@0 111 typedef Iter INHERITED;
michael@0 112 };
michael@0 113
michael@0 114 private:
michael@0 115 // allow unit test to call numBlocksAllocated
michael@0 116 friend class DequeUnitTestHelper;
michael@0 117
michael@0 118 void* fFront;
michael@0 119 void* fBack;
michael@0 120
michael@0 121 Block* fFrontBlock;
michael@0 122 Block* fBackBlock;
michael@0 123 size_t fElemSize;
michael@0 124 void* fInitialStorage;
michael@0 125 int fCount; // number of elements in the deque
michael@0 126 int fAllocCount; // number of elements to allocate per block
michael@0 127
michael@0 128 Block* allocateBlock(int allocCount);
michael@0 129 void freeBlock(Block* block);
michael@0 130
michael@0 131 /**
michael@0 132 * This returns the number of chunk blocks allocated by the deque. It
michael@0 133 * can be used to gauge the effectiveness of the selected allocCount.
michael@0 134 */
michael@0 135 int numBlocksAllocated() const;
michael@0 136 };
michael@0 137
michael@0 138 #endif

mercurial