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

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: 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 % 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
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
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