gfx/skia/trunk/src/core/SkPtrRecorder.cpp

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 2011 Google Inc.
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 #include "SkPtrRecorder.h"
michael@0 9 #include "SkTSearch.h"
michael@0 10
michael@0 11 void SkPtrSet::reset() {
michael@0 12 Pair* p = fList.begin();
michael@0 13 Pair* stop = fList.end();
michael@0 14 while (p < stop) {
michael@0 15 this->decPtr(p->fPtr);
michael@0 16 p += 1;
michael@0 17 }
michael@0 18 fList.reset();
michael@0 19 }
michael@0 20
michael@0 21 bool SkPtrSet::Less(const Pair& a, const Pair& b) {
michael@0 22 return (char*)a.fPtr < (char*)b.fPtr;
michael@0 23 }
michael@0 24
michael@0 25 uint32_t SkPtrSet::find(void* ptr) const {
michael@0 26 if (NULL == ptr) {
michael@0 27 return 0;
michael@0 28 }
michael@0 29
michael@0 30 int count = fList.count();
michael@0 31 Pair pair;
michael@0 32 pair.fPtr = ptr;
michael@0 33
michael@0 34 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
michael@0 35 if (index < 0) {
michael@0 36 return 0;
michael@0 37 }
michael@0 38 return fList[index].fIndex;
michael@0 39 }
michael@0 40
michael@0 41 uint32_t SkPtrSet::add(void* ptr) {
michael@0 42 if (NULL == ptr) {
michael@0 43 return 0;
michael@0 44 }
michael@0 45
michael@0 46 int count = fList.count();
michael@0 47 Pair pair;
michael@0 48 pair.fPtr = ptr;
michael@0 49
michael@0 50 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
michael@0 51 if (index < 0) {
michael@0 52 index = ~index; // turn it back into an index for insertion
michael@0 53 this->incPtr(ptr);
michael@0 54 pair.fIndex = count + 1;
michael@0 55 *fList.insert(index) = pair;
michael@0 56 return count + 1;
michael@0 57 } else {
michael@0 58 return fList[index].fIndex;
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 void SkPtrSet::copyToArray(void* array[]) const {
michael@0 63 int count = fList.count();
michael@0 64 if (count > 0) {
michael@0 65 SkASSERT(array);
michael@0 66 const Pair* p = fList.begin();
michael@0 67 // p->fIndex is base-1, so we need to subtract to find its slot
michael@0 68 for (int i = 0; i < count; i++) {
michael@0 69 int index = p[i].fIndex - 1;
michael@0 70 SkASSERT((unsigned)index < (unsigned)count);
michael@0 71 array[index] = p[i].fPtr;
michael@0 72 }
michael@0 73 }
michael@0 74 }

mercurial