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) | 19 SkBitSet::SkBitSet(const SkBitSet& source) |
20 : fBitData(nullptr), fDwordCount(0), fBitCount(0) { | 20 : fBitData(nullptr), fDwordCount(0), fBitCount(0) { |
21 *this = source; | 21 *this = source; |
22 } | 22 } |
23 | 23 |
| 24 SkBitSet::SkBitSet(SkBitSet&& source) |
| 25 : fBitData(source.fBitData.release()) |
| 26 , fDwordCount(source.fDwordCount) |
| 27 , fBitCount(source.fBitCount) { |
| 28 source.fDwordCount = 0; |
| 29 source.fBitCount = 0; |
| 30 } |
| 31 |
24 SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) { | 32 SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) { |
25 if (this == &rhs) { | 33 if (this == &rhs) { |
26 return *this; | 34 return *this; |
27 } | 35 } |
28 fBitCount = rhs.fBitCount; | 36 fBitCount = rhs.fBitCount; |
29 fBitData.reset(); | 37 fBitData.reset(); |
30 fDwordCount = rhs.fDwordCount; | 38 fDwordCount = rhs.fDwordCount; |
31 fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t))); | 39 fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t))); |
32 memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t)); | 40 memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t)); |
33 return *this; | 41 return *this; |
(...skipping 24 matching lines...) Expand all Loading... |
58 if (fBitCount != source.fBitCount) { | 66 if (fBitCount != source.fBitCount) { |
59 return false; | 67 return false; |
60 } | 68 } |
61 uint32_t* targetBitmap = this->internalGet(0); | 69 uint32_t* targetBitmap = this->internalGet(0); |
62 uint32_t* sourceBitmap = source.internalGet(0); | 70 uint32_t* sourceBitmap = source.internalGet(0); |
63 for (size_t i = 0; i < fDwordCount; ++i) { | 71 for (size_t i = 0; i < fDwordCount; ++i) { |
64 targetBitmap[i] |= sourceBitmap[i]; | 72 targetBitmap[i] |= sourceBitmap[i]; |
65 } | 73 } |
66 return true; | 74 return true; |
67 } | 75 } |
OLD | NEW |