Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: src/utils/SkBitSet.h

Issue 640243003: Small improvements to SkBitSet: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reed Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/utils/SkBitSet.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | src/utils/SkBitSet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698