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.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "SkPtrRecorder.h"
     9 #include "SkTSearch.h"
    11 void SkPtrSet::reset() {
    12     Pair* p = fList.begin();
    13     Pair* stop = fList.end();
    14     while (p < stop) {
    15         this->decPtr(p->fPtr);
    16         p += 1;
    17     }
    18     fList.reset();
    19 }
    21 bool SkPtrSet::Less(const Pair& a, const Pair& b) {
    22     return (char*)a.fPtr < (char*)b.fPtr;
    23 }
    25 uint32_t SkPtrSet::find(void* ptr) const {
    26     if (NULL == ptr) {
    27         return 0;
    28     }
    30     int count = fList.count();
    31     Pair pair;
    32     pair.fPtr = ptr;
    34     int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
    35     if (index < 0) {
    36         return 0;
    37     }
    38     return fList[index].fIndex;
    39 }
    41 uint32_t SkPtrSet::add(void* ptr) {
    42     if (NULL == ptr) {
    43         return 0;
    44     }
    46     int count = fList.count();
    47     Pair pair;
    48     pair.fPtr = ptr;
    50     int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
    51     if (index < 0) {
    52         index = ~index; // turn it back into an index for insertion
    53         this->incPtr(ptr);
    54         pair.fIndex = count + 1;
    55         *fList.insert(index) = pair;
    56         return count + 1;
    57     } else {
    58         return fList[index].fIndex;
    59     }
    60 }
    62 void SkPtrSet::copyToArray(void* array[]) const {
    63     int count = fList.count();
    64     if (count > 0) {
    65         SkASSERT(array);
    66         const Pair* p = fList.begin();
    67         // p->fIndex is base-1, so we need to subtract to find its slot
    68         for (int i = 0; i < count; i++) {
    69             int index = p[i].fIndex - 1;
    70             SkASSERT((unsigned)index < (unsigned)count);
    71             array[index] = p[i].fPtr;
    72         }
    73     }
    74 }

mercurial