gfx/skia/trunk/src/utils/SkBitSet.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 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
michael@0 9
michael@0 10 #ifndef SkBitSet_DEFINED
michael@0 11 #define SkBitSet_DEFINED
michael@0 12
michael@0 13 #include "SkTypes.h"
michael@0 14 #include "SkTDArray.h"
michael@0 15
michael@0 16 class SkBitSet {
michael@0 17 public:
michael@0 18 /** NumberOfBits must be greater than zero.
michael@0 19 */
michael@0 20 explicit SkBitSet(int numberOfBits);
michael@0 21 explicit SkBitSet(const SkBitSet& source);
michael@0 22
michael@0 23 SkBitSet& operator=(const SkBitSet& rhs);
michael@0 24 bool operator==(const SkBitSet& rhs);
michael@0 25 bool operator!=(const SkBitSet& rhs);
michael@0 26
michael@0 27 /** Clear all data.
michael@0 28 */
michael@0 29 void clearAll();
michael@0 30
michael@0 31 /** Set the value of the index-th bit.
michael@0 32 */
michael@0 33 void setBit(int index, bool value);
michael@0 34
michael@0 35 /** Test if bit index is set.
michael@0 36 */
michael@0 37 bool isBitSet(int index) const;
michael@0 38
michael@0 39 /** Or bits from source. false is returned if this doesn't have the same
michael@0 40 * bit count as source.
michael@0 41 */
michael@0 42 bool orBits(const SkBitSet& source);
michael@0 43
michael@0 44 /** Export indices of set bits to T array.
michael@0 45 */
michael@0 46 template<typename T>
michael@0 47 void exportTo(SkTDArray<T>* array) const {
michael@0 48 SkASSERT(array);
michael@0 49 uint32_t* data = reinterpret_cast<uint32_t*>(fBitData.get());
michael@0 50 for (unsigned int i = 0; i < fDwordCount; ++i) {
michael@0 51 uint32_t value = data[i];
michael@0 52 if (value) { // There are set bits
michael@0 53 unsigned int index = i * 32;
michael@0 54 for (unsigned int j = 0; j < 32; ++j) {
michael@0 55 if (0x1 & (value >> j)) {
michael@0 56 array->push(index + j);
michael@0 57 }
michael@0 58 }
michael@0 59 }
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 private:
michael@0 64 SkAutoFree fBitData;
michael@0 65 // Dword (32-bit) count of the bitset.
michael@0 66 size_t fDwordCount;
michael@0 67 size_t fBitCount;
michael@0 68
michael@0 69 uint32_t* internalGet(int index) const {
michael@0 70 SkASSERT((size_t)index < fBitCount);
michael@0 71 size_t internalIndex = index / 32;
michael@0 72 SkASSERT(internalIndex < fDwordCount);
michael@0 73 return reinterpret_cast<uint32_t*>(fBitData.get()) + internalIndex;
michael@0 74 }
michael@0 75 };
michael@0 76
michael@0 77
michael@0 78 #endif

mercurial