OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkBitSet_DEFINED | 10 #ifndef SkBitSet_DEFINED |
(...skipping 12 matching lines...) Expand all Loading... |
23 SkBitSet& operator=(const SkBitSet& rhs); | 23 SkBitSet& operator=(const SkBitSet& rhs); |
24 bool operator==(const SkBitSet& rhs); | 24 bool operator==(const SkBitSet& rhs); |
25 bool operator!=(const SkBitSet& rhs); | 25 bool operator!=(const SkBitSet& rhs); |
26 | 26 |
27 /** Clear all data. | 27 /** Clear all data. |
28 */ | 28 */ |
29 void clearAll(); | 29 void clearAll(); |
30 | 30 |
31 /** Set the value of the index-th bit. | 31 /** Set the value of the index-th bit. |
32 */ | 32 */ |
33 void setBit(int index, bool value); | 33 void setBit(int index, bool value) { |
| 34 uint32_t mask = 1 << (index & 31); |
| 35 uint32_t* chunk = this->internalGet(index); |
| 36 if (value) { |
| 37 *chunk |= mask; |
| 38 } else { |
| 39 *chunk &= ~mask; |
| 40 } |
| 41 } |
34 | 42 |
35 /** Test if bit index is set. | 43 /** Test if bit index is set. |
36 */ | 44 */ |
37 bool isBitSet(int index) const; | 45 bool isBitSet(int index) const { |
| 46 uint32_t mask = 1 << (index & 31); |
| 47 return SkToBool(*this->internalGet(index) & mask); |
| 48 } |
38 | 49 |
39 /** Or bits from source. false is returned if this doesn't have the same | 50 /** Or bits from source. false is returned if this doesn't have the same |
40 * bit count as source. | 51 * bit count as source. |
41 */ | 52 */ |
42 bool orBits(const SkBitSet& source); | 53 bool orBits(const SkBitSet& source); |
43 | 54 |
44 /** Export indices of set bits to T array. | 55 /** Export indices of set bits to T array. |
45 */ | 56 */ |
46 template<typename T> | 57 template<typename T> |
47 void exportTo(SkTDArray<T>* array) const { | 58 void exportTo(SkTDArray<T>* array) const { |
(...skipping 21 matching lines...) Expand all Loading... |
69 uint32_t* internalGet(int index) const { | 80 uint32_t* internalGet(int index) const { |
70 SkASSERT((size_t)index < fBitCount); | 81 SkASSERT((size_t)index < fBitCount); |
71 size_t internalIndex = index / 32; | 82 size_t internalIndex = index / 32; |
72 SkASSERT(internalIndex < fDwordCount); | 83 SkASSERT(internalIndex < fDwordCount); |
73 return reinterpret_cast<uint32_t*>(fBitData.get()) + internalIndex; | 84 return reinterpret_cast<uint32_t*>(fBitData.get()) + internalIndex; |
74 } | 85 } |
75 }; | 86 }; |
76 | 87 |
77 | 88 |
78 #endif | 89 #endif |
OLD | NEW |