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

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

Issue 2265623002: src/utils/SkBitSet: simplify (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-19 (Friday) 16:05:19 EDT Created 4 years, 4 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 | « src/utils/SkBitSet.h ('k') | src/xps/SkXPSDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9 #include "SkBitSet.h"
10
11 SkBitSet::SkBitSet(int numberOfBits)
12 : fBitData(nullptr), fDwordCount(0), fBitCount(numberOfBits) {
13 SkASSERT(numberOfBits > 0);
14 // Round up size to 32-bit boundary.
15 fDwordCount = (numberOfBits + 31) / 32;
16 fBitData.set(sk_calloc_throw(fDwordCount * sizeof(uint32_t)));
17 }
18
19 SkBitSet::SkBitSet(SkBitSet&& source)
20 : fBitData(source.fBitData.release())
21 , fDwordCount(source.fDwordCount)
22 , fBitCount(source.fBitCount) {
23 source.fDwordCount = 0;
24 source.fBitCount = 0;
25 }
26
27 SkBitSet& SkBitSet::operator=(SkBitSet&& rhs) {
28 if (this != &rhs) {
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 }
36 return *this;
37 }
38
39 bool SkBitSet::operator==(const SkBitSet& rhs) {
40 if (fBitCount == rhs.fBitCount) {
41 if (fBitData.get() != nullptr) {
42 return (memcmp(fBitData.get(), rhs.fBitData.get(),
43 fDwordCount * sizeof(uint32_t)) == 0);
44 }
45 return true;
46 }
47 return false;
48 }
49
50 bool SkBitSet::operator!=(const SkBitSet& rhs) {
51 return !(*this == rhs);
52 }
53
54 void SkBitSet::clearAll() {
55 if (fBitData.get() != nullptr) {
56 sk_bzero(fBitData.get(), fDwordCount * sizeof(uint32_t));
57 }
58 }
59
60 bool SkBitSet::orBits(const SkBitSet& source) {
61 if (fBitCount != source.fBitCount) {
62 return false;
63 }
64 uint32_t* targetBitmap = this->internalGet(0);
65 uint32_t* sourceBitmap = source.internalGet(0);
66 for (size_t i = 0; i < fDwordCount; ++i) {
67 targetBitmap[i] |= sourceBitmap[i];
68 }
69 return true;
70 }
OLDNEW
« no previous file with comments | « src/utils/SkBitSet.h ('k') | src/xps/SkXPSDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698