| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkBitSet_DEFINED | 8 #ifndef SkBitSet_DEFINED |
| 9 #define SkBitSet_DEFINED | 9 #define SkBitSet_DEFINED |
| 10 | 10 |
| 11 #include "SkTDArray.h" | 11 #include "SkTDArray.h" |
| 12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 13 | 13 |
| 14 class SkBitSet { | 14 class SkBitSet { |
| 15 public: | 15 public: |
| 16 explicit SkBitSet(int numberOfBits) { | 16 explicit SkBitSet(int numberOfBits) { |
| 17 SkASSERT(numberOfBits > 0); | 17 SkASSERT(numberOfBits >= 0); |
| 18 fDwordCount = (numberOfBits + 31) / 32; // Round up size to 32-bit boun
dary. | 18 fDwordCount = (numberOfBits + 31) / 32; // Round up size to 32-bit boun
dary. |
| 19 fBitData.reset((uint32_t*)sk_calloc_throw(fDwordCount * sizeof(uint32_t)
)); | 19 if (fDwordCount > 0) { |
| 20 fBitData.reset((uint32_t*)sk_calloc_throw(fDwordCount * sizeof(uint3
2_t))); |
| 21 } |
| 20 } | 22 } |
| 21 | 23 |
| 22 SkBitSet(const SkBitSet&) = delete; | 24 SkBitSet(const SkBitSet&) = delete; |
| 23 SkBitSet& operator=(const SkBitSet&) = delete; | 25 SkBitSet& operator=(const SkBitSet&) = delete; |
| 24 | 26 |
| 25 /** Set the value of the index-th bit to true. */ | 27 /** Set the value of the index-th bit to true. */ |
| 26 void set(int index) { | 28 void set(int index) { |
| 27 uint32_t mask = 1 << (index & 31); | 29 uint32_t mask = 1 << (index & 31); |
| 28 uint32_t* chunk = this->internalGet(index); | 30 uint32_t* chunk = this->internalGet(index); |
| 29 SkASSERT(chunk); | 31 SkASSERT(chunk); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 size_t internalIndex = index / 32; | 73 size_t internalIndex = index / 32; |
| 72 if (internalIndex >= fDwordCount) { | 74 if (internalIndex >= fDwordCount) { |
| 73 return nullptr; | 75 return nullptr; |
| 74 } | 76 } |
| 75 return fBitData.get() + internalIndex; | 77 return fBitData.get() + internalIndex; |
| 76 } | 78 } |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 | 81 |
| 80 #endif | 82 #endif |
| OLD | NEW |