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 | 8 |
9 #include "SkBitSet.h" | 9 #include "SkBitSet.h" |
10 | 10 |
11 SkBitSet::SkBitSet(int numberOfBits) | 11 SkBitSet::SkBitSet(int numberOfBits) |
12 : fBitData(nullptr), fDwordCount(0), fBitCount(numberOfBits) { | 12 : fBitData(nullptr), fDwordCount(0), fBitCount(numberOfBits) { |
13 SkASSERT(numberOfBits > 0); | 13 SkASSERT(numberOfBits > 0); |
14 // Round up size to 32-bit boundary. | 14 // Round up size to 32-bit boundary. |
15 fDwordCount = (numberOfBits + 31) / 32; | 15 fDwordCount = (numberOfBits + 31) / 32; |
16 fBitData.set(sk_calloc_throw(fDwordCount * sizeof(uint32_t))); | 16 fBitData.set(sk_calloc_throw(fDwordCount * sizeof(uint32_t))); |
17 } | 17 } |
18 | 18 |
19 SkBitSet::SkBitSet(const SkBitSet& source) | |
20 : fBitData(nullptr), fDwordCount(0), fBitCount(0) { | |
21 *this = source; | |
22 } | |
23 | |
24 SkBitSet::SkBitSet(SkBitSet&& source) | 19 SkBitSet::SkBitSet(SkBitSet&& source) |
25 : fBitData(source.fBitData.release()) | 20 : fBitData(source.fBitData.release()) |
26 , fDwordCount(source.fDwordCount) | 21 , fDwordCount(source.fDwordCount) |
27 , fBitCount(source.fBitCount) { | 22 , fBitCount(source.fBitCount) { |
28 source.fDwordCount = 0; | 23 source.fDwordCount = 0; |
29 source.fBitCount = 0; | 24 source.fBitCount = 0; |
30 } | 25 } |
31 | 26 |
32 SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) { | 27 SkBitSet& SkBitSet::operator=(SkBitSet&& rhs) { |
33 if (this == &rhs) { | 28 if (this != &rhs) { |
34 return *this; | 29 fBitCount = rhs.fBitCount; |
| 30 fDwordCount = rhs.fDwordCount; |
| 31 fBitData.reset(); // Free old pointer. |
| 32 fBitData.set(rhs.fBitData.release()); |
| 33 rhs.fBitCount = 0; |
| 34 rhs.fDwordCount = 0; |
35 } | 35 } |
36 fBitCount = rhs.fBitCount; | |
37 fBitData.reset(); | |
38 fDwordCount = rhs.fDwordCount; | |
39 fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t))); | |
40 memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t)); | |
41 return *this; | 36 return *this; |
42 } | 37 } |
43 | 38 |
44 bool SkBitSet::operator==(const SkBitSet& rhs) { | 39 bool SkBitSet::operator==(const SkBitSet& rhs) { |
45 if (fBitCount == rhs.fBitCount) { | 40 if (fBitCount == rhs.fBitCount) { |
46 if (fBitData.get() != nullptr) { | 41 if (fBitData.get() != nullptr) { |
47 return (memcmp(fBitData.get(), rhs.fBitData.get(), | 42 return (memcmp(fBitData.get(), rhs.fBitData.get(), |
48 fDwordCount * sizeof(uint32_t)) == 0); | 43 fDwordCount * sizeof(uint32_t)) == 0); |
49 } | 44 } |
50 return true; | 45 return true; |
(...skipping 15 matching lines...) Expand all Loading... |
66 if (fBitCount != source.fBitCount) { | 61 if (fBitCount != source.fBitCount) { |
67 return false; | 62 return false; |
68 } | 63 } |
69 uint32_t* targetBitmap = this->internalGet(0); | 64 uint32_t* targetBitmap = this->internalGet(0); |
70 uint32_t* sourceBitmap = source.internalGet(0); | 65 uint32_t* sourceBitmap = source.internalGet(0); |
71 for (size_t i = 0; i < fDwordCount; ++i) { | 66 for (size_t i = 0; i < fDwordCount; ++i) { |
72 targetBitmap[i] |= sourceBitmap[i]; | 67 targetBitmap[i] |= sourceBitmap[i]; |
73 } | 68 } |
74 return true; | 69 return true; |
75 } | 70 } |
OLD | NEW |