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 % 32); | |
reed1
2014/10/09 15:53:43
nit: in skia using % 32 is far more rare than (ind
mtklein
2014/10/09 16:12:59
Done.
Generated code looks fine to me both ways,
| |
35 if (value) { | |
36 *(this->internalGet(index)) |= mask; | |
reed1
2014/10/09 15:53:43
stylistic:
uint32_t mask = ...
uint32_t* chunk =
mtklein
2014/10/09 16:12:59
Done.
For what it's worth, it had better only cal
| |
37 } else { | |
38 *(this->internalGet(index)) &= ~mask; | |
39 } | |
40 } | |
34 | 41 |
35 /** Test if bit index is set. | 42 /** Test if bit index is set. |
36 */ | 43 */ |
37 bool isBitSet(int index) const; | 44 bool isBitSet(int index) const { |
45 uint32_t mask = 1 << (index % 32); | |
46 return 0 != (*this->internalGet(index) & mask); | |
reed1
2014/10/09 15:53:43
trivial nit: use SkToBool(...) instead?
mtklein
2014/10/09 16:12:59
Done.
| |
47 } | |
38 | 48 |
39 /** Or bits from source. false is returned if this doesn't have the same | 49 /** Or bits from source. false is returned if this doesn't have the same |
40 * bit count as source. | 50 * bit count as source. |
41 */ | 51 */ |
42 bool orBits(const SkBitSet& source); | 52 bool orBits(const SkBitSet& source); |
43 | 53 |
44 /** Export indices of set bits to T array. | 54 /** Export indices of set bits to T array. |
45 */ | 55 */ |
46 template<typename T> | 56 template<typename T> |
47 void exportTo(SkTDArray<T>* array) const { | 57 void exportTo(SkTDArray<T>* array) const { |
(...skipping 21 matching lines...) Expand all Loading... | |
69 uint32_t* internalGet(int index) const { | 79 uint32_t* internalGet(int index) const { |
70 SkASSERT((size_t)index < fBitCount); | 80 SkASSERT((size_t)index < fBitCount); |
71 size_t internalIndex = index / 32; | 81 size_t internalIndex = index / 32; |
72 SkASSERT(internalIndex < fDwordCount); | 82 SkASSERT(internalIndex < fDwordCount); |
73 return reinterpret_cast<uint32_t*>(fBitData.get()) + internalIndex; | 83 return reinterpret_cast<uint32_t*>(fBitData.get()) + internalIndex; |
74 } | 84 } |
75 }; | 85 }; |
76 | 86 |
77 | 87 |
78 #endif | 88 #endif |
OLD | NEW |