gfx/skia/trunk/include/core/SkTDStack.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 SkTDStack_DEFINED
michael@0 11 #define SkTDStack_DEFINED
michael@0 12
michael@0 13 #include "SkTypes.h"
michael@0 14
michael@0 15 template <typename T> class SkTDStack : SkNoncopyable {
michael@0 16 public:
michael@0 17 SkTDStack() : fCount(0), fTotalCount(0) {
michael@0 18 fInitialRec.fNext = NULL;
michael@0 19 fRec = &fInitialRec;
michael@0 20
michael@0 21 // fCount = kSlotCount;
michael@0 22 }
michael@0 23
michael@0 24 ~SkTDStack() {
michael@0 25 Rec* rec = fRec;
michael@0 26 while (rec != &fInitialRec) {
michael@0 27 Rec* next = rec->fNext;
michael@0 28 sk_free(rec);
michael@0 29 rec = next;
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 int count() const { return fTotalCount; }
michael@0 34 int depth() const { return fTotalCount; }
michael@0 35 bool empty() const { return fTotalCount == 0; }
michael@0 36
michael@0 37 T* push() {
michael@0 38 SkASSERT(fCount <= kSlotCount);
michael@0 39 if (fCount == kSlotCount) {
michael@0 40 Rec* rec = (Rec*)sk_malloc_throw(sizeof(Rec));
michael@0 41 rec->fNext = fRec;
michael@0 42 fRec = rec;
michael@0 43 fCount = 0;
michael@0 44 }
michael@0 45 ++fTotalCount;
michael@0 46 return &fRec->fSlots[fCount++];
michael@0 47 }
michael@0 48
michael@0 49 void push(const T& elem) { *this->push() = elem; }
michael@0 50
michael@0 51 const T& index(int idx) const {
michael@0 52 SkASSERT(fRec && fCount > idx);
michael@0 53 return fRec->fSlots[fCount - idx - 1];
michael@0 54 }
michael@0 55
michael@0 56 T& index(int idx) {
michael@0 57 SkASSERT(fRec && fCount > idx);
michael@0 58 return fRec->fSlots[fCount - idx - 1];
michael@0 59 }
michael@0 60
michael@0 61 const T& top() const {
michael@0 62 SkASSERT(fRec && fCount > 0);
michael@0 63 return fRec->fSlots[fCount - 1];
michael@0 64 }
michael@0 65
michael@0 66 T& top() {
michael@0 67 SkASSERT(fRec && fCount > 0);
michael@0 68 return fRec->fSlots[fCount - 1];
michael@0 69 }
michael@0 70
michael@0 71 void pop(T* elem) {
michael@0 72 if (elem) {
michael@0 73 *elem = fRec->fSlots[fCount - 1];
michael@0 74 }
michael@0 75 this->pop();
michael@0 76 }
michael@0 77
michael@0 78 void pop() {
michael@0 79 SkASSERT(fCount > 0 && fRec);
michael@0 80 --fTotalCount;
michael@0 81 if (--fCount == 0) {
michael@0 82 if (fRec != &fInitialRec) {
michael@0 83 Rec* rec = fRec->fNext;
michael@0 84 sk_free(fRec);
michael@0 85 fCount = kSlotCount;
michael@0 86 fRec = rec;
michael@0 87 } else {
michael@0 88 SkASSERT(fTotalCount == 0);
michael@0 89 }
michael@0 90 }
michael@0 91 }
michael@0 92
michael@0 93 private:
michael@0 94 enum {
michael@0 95 kSlotCount = 8
michael@0 96 };
michael@0 97
michael@0 98 struct Rec;
michael@0 99 friend struct Rec;
michael@0 100
michael@0 101 struct Rec {
michael@0 102 Rec* fNext;
michael@0 103 T fSlots[kSlotCount];
michael@0 104 };
michael@0 105 Rec fInitialRec;
michael@0 106 Rec* fRec;
michael@0 107 int fCount, fTotalCount;
michael@0 108 };
michael@0 109
michael@0 110 #endif

mercurial