Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | QBitArray::QBitArray(int size, bool value) | - |
5 | { | - |
6 | if (!size) { evaluated: !size yes Evaluation Count:703 | yes Evaluation Count:18431 |
| 703-18431 |
7 | d.resize(0); | - |
8 | return; executed: return; Execution Count:703 | 703 |
9 | } | - |
10 | d.resize(1 + (size+7)/8); | - |
11 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - |
12 | memset(c, value ? 0xff : 0, d.size()); | - |
13 | *c = d.size()*8 - size; | - |
14 | if (value && size && size % 8) evaluated: value yes Evaluation Count:4039 | yes Evaluation Count:14392 |
partially evaluated: size yes Evaluation Count:4039 | no Evaluation Count:0 |
evaluated: size % 8 yes Evaluation Count:3532 | yes Evaluation Count:507 |
| 0-14392 |
15 | *(c+1+size/8) &= (1 << (size%8)) - 1; executed: *(c+1+size/8) &= (1 << (size%8)) - 1; Execution Count:3532 | 3532 |
16 | } executed: } Execution Count:18431 | 18431 |
17 | int QBitArray::count(bool on) const | - |
18 | { | - |
19 | int numBits = 0; | - |
20 | int len = size(); | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1; | - |
27 | while (len >= 32) { evaluated: len >= 32 yes Evaluation Count:1000548 | yes Evaluation Count:16147 |
| 16147-1000548 |
28 | quint32 v = quint32(bits[0]) | (quint32(bits[1]) << 8) | (quint32(bits[2]) << 16) | (quint32(bits[3]) << 24); | - |
29 | quint32 c = ((v & 0xfff) * static_cast<unsigned long long>(0x1001001001001ULL) & static_cast<unsigned long long>(0x84210842108421ULL)) % 0x1f; | - |
30 | c += (((v & 0xfff000) >> 12) * static_cast<unsigned long long>(0x1001001001001ULL) & static_cast<unsigned long long>(0x84210842108421ULL)) % 0x1f; | - |
31 | c += ((v >> 24) * static_cast<unsigned long long>(0x1001001001001ULL) & static_cast<unsigned long long>(0x84210842108421ULL)) % 0x1f; | - |
32 | len -= 32; | - |
33 | bits += 4; | - |
34 | numBits += int(c); | - |
35 | } executed: } Execution Count:1000548 | 1000548 |
36 | while (len >= 24) { evaluated: len >= 24 yes Evaluation Count:4012 | yes Evaluation Count:16147 |
| 4012-16147 |
37 | quint32 v = quint32(bits[0]) | (quint32(bits[1]) << 8) | (quint32(bits[2]) << 16); | - |
38 | quint32 c = ((v & 0xfff) * static_cast<unsigned long long>(0x1001001001001ULL) & static_cast<unsigned long long>(0x84210842108421ULL)) % 0x1f; | - |
39 | c += (((v & 0xfff000) >> 12) * static_cast<unsigned long long>(0x1001001001001ULL) & static_cast<unsigned long long>(0x84210842108421ULL)) % 0x1f; | - |
40 | len -= 24; | - |
41 | bits += 3; | - |
42 | numBits += int(c); | - |
43 | } executed: } Execution Count:4012 | 4012 |
44 | while (len >= 0) { evaluated: len >= 0 yes Evaluation Count:168962 | yes Evaluation Count:16147 |
| 16147-168962 |
45 | if (bits[len / 8] & (1 << ((len - 1) & 7))) evaluated: bits[len / 8] & (1 << ((len - 1) & 7)) yes Evaluation Count:76393 | yes Evaluation Count:92569 |
| 76393-92569 |
46 | ++numBits; executed: ++numBits; Execution Count:76393 | 76393 |
47 | --len; | - |
48 | } executed: } Execution Count:168962 | 168962 |
49 | | - |
50 | return on ? numBits : size() - numBits; executed: return on ? numBits : size() - numBits; Execution Count:16147 | 16147 |
51 | } | - |
52 | void QBitArray::resize(int size) | - |
53 | { | - |
54 | if (!size) { evaluated: !size yes Evaluation Count:52 | yes Evaluation Count:4638 |
| 52-4638 |
55 | d.resize(0); | - |
56 | } else { executed: } Execution Count:52 | 52 |
57 | int s = d.size(); | - |
58 | d.resize(1 + (size+7)/8); | - |
59 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - |
60 | if (size > (s << 3)) evaluated: size > (s << 3) yes Evaluation Count:555 | yes Evaluation Count:4083 |
| 555-4083 |
61 | memset(c + s, 0, d.size() - s); executed: memset(c + s, 0, d.size() - s); Execution Count:555 | 555 |
62 | else if ( size % 8) evaluated: size % 8 yes Evaluation Count:3569 | yes Evaluation Count:514 |
| 514-3569 |
63 | *(c+1+size/8) &= (1 << (size%8)) - 1; executed: *(c+1+size/8) &= (1 << (size%8)) - 1; Execution Count:3569 | 3569 |
64 | *c = d.size()*8 - size; | - |
65 | } executed: } Execution Count:4638 | 4638 |
66 | } | - |
67 | void QBitArray::fill(bool value, int begin, int end) | - |
68 | { | - |
69 | while (begin < end && begin & 0x7) evaluated: begin < end yes Evaluation Count:533 | yes Evaluation Count:65 |
evaluated: begin & 0x7 yes Evaluation Count:425 | yes Evaluation Count:108 |
| 65-533 |
70 | setBit(begin++, value); executed: setBit(begin++, value); Execution Count:425 | 425 |
71 | int len = end - begin; | - |
72 | if (len <= 0) evaluated: len <= 0 yes Evaluation Count:65 | yes Evaluation Count:108 |
| 65-108 |
73 | return; executed: return; Execution Count:65 | 65 |
74 | int s = len & ~0x7; | - |
75 | uchar *c = reinterpret_cast<uchar*>(d.data()); | - |
76 | memset(c + (begin >> 3) + 1, value ? 0xff : 0, s >> 3); | - |
77 | begin += s; | - |
78 | while (begin < end) evaluated: begin < end yes Evaluation Count:354 | yes Evaluation Count:108 |
| 108-354 |
79 | setBit(begin++, value); executed: setBit(begin++, value); Execution Count:354 | 354 |
80 | } executed: } Execution Count:108 | 108 |
81 | QBitArray &QBitArray::operator&=(const QBitArray &other) | - |
82 | { | - |
83 | resize(qMax(size(), other.size())); | - |
84 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - |
85 | const uchar *a2 = reinterpret_cast<const uchar*>(other.d.constData()) + 1; | - |
86 | int n = other.d.size() -1 ; | - |
87 | int p = d.size() - 1 - n; | - |
88 | while (n-- > 0) evaluated: n-- > 0 yes Evaluation Count:9 | yes Evaluation Count:8 |
| 8-9 |
89 | *a1++ &= *a2++; executed: *a1++ &= *a2++; Execution Count:9 | 9 |
90 | while (p-- > 0) evaluated: p-- > 0 yes Evaluation Count:4 | yes Evaluation Count:8 |
| 4-8 |
91 | *a1++ = 0; executed: *a1++ = 0; Execution Count:4 | 4 |
92 | return *this; executed: return *this; Execution Count:8 | 8 |
93 | } | - |
94 | QBitArray &QBitArray::operator|=(const QBitArray &other) | - |
95 | { | - |
96 | resize(qMax(size(), other.size())); | - |
97 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - |
98 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - |
99 | int n = other.d.size() - 1; | - |
100 | while (n-- > 0) evaluated: n-- > 0 yes Evaluation Count:8 | yes Evaluation Count:8 |
| 8 |
101 | *a1++ |= *a2++; executed: *a1++ |= *a2++; Execution Count:8 | 8 |
102 | return *this; executed: return *this; Execution Count:8 | 8 |
103 | } | - |
104 | QBitArray &QBitArray::operator^=(const QBitArray &other) | - |
105 | { | - |
106 | resize(qMax(size(), other.size())); | - |
107 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - |
108 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - |
109 | int n = other.d.size() - 1; | - |
110 | while (n-- > 0) evaluated: n-- > 0 yes Evaluation Count:9 | yes Evaluation Count:8 |
| 8-9 |
111 | *a1++ ^= *a2++; executed: *a1++ ^= *a2++; Execution Count:9 | 9 |
112 | return *this; executed: return *this; Execution Count:8 | 8 |
113 | } | - |
114 | QBitArray QBitArray::operator~() const | - |
115 | { | - |
116 | int sz = size(); | - |
117 | QBitArray a(sz); | - |
118 | const uchar *a1 = reinterpret_cast<const uchar *>(d.constData()) + 1; | - |
119 | uchar *a2 = reinterpret_cast<uchar*>(a.d.data()) + 1; | - |
120 | int n = d.size() - 1; | - |
121 | | - |
122 | while (n-- > 0) evaluated: n-- > 0 yes Evaluation Count:13 | yes Evaluation Count:13 |
| 13 |
123 | *a2++ = ~*a1++; executed: *a2++ = ~*a1++; Execution Count:13 | 13 |
124 | | - |
125 | if (sz && sz%8) evaluated: sz yes Evaluation Count:11 | yes Evaluation Count:2 |
evaluated: sz%8 yes Evaluation Count:6 | yes Evaluation Count:5 |
| 2-11 |
126 | *(a2-1) &= (1 << (sz%8)) - 1; executed: *(a2-1) &= (1 << (sz%8)) - 1; Execution Count:6 | 6 |
127 | return a; executed: return a; Execution Count:13 | 13 |
128 | } | - |
129 | QBitArray operator&(const QBitArray &a1, const QBitArray &a2) | - |
130 | { | - |
131 | QBitArray tmp = a1; | - |
132 | tmp &= a2; | - |
133 | return tmp; never executed: return tmp; | 0 |
134 | } | - |
135 | QBitArray operator|(const QBitArray &a1, const QBitArray &a2) | - |
136 | { | - |
137 | QBitArray tmp = a1; | - |
138 | tmp |= a2; | - |
139 | return tmp; never executed: return tmp; | 0 |
140 | } | - |
141 | QBitArray operator^(const QBitArray &a1, const QBitArray &a2) | - |
142 | { | - |
143 | QBitArray tmp = a1; | - |
144 | tmp ^= a2; | - |
145 | return tmp; never executed: return tmp; | 0 |
146 | } | - |
147 | QDataStream &operator<<(QDataStream &out, const QBitArray &ba) | - |
148 | { | - |
149 | quint32 len = ba.size(); | - |
150 | out << len; | - |
151 | if (len > 0) evaluated: len > 0 yes Evaluation Count:140 | yes Evaluation Count:212 |
| 140-212 |
152 | out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1); executed: out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1); Execution Count:140 | 140 |
153 | return out; executed: return out; Execution Count:352 | 352 |
154 | } | - |
155 | QDataStream &operator>>(QDataStream &in, QBitArray &ba) | - |
156 | { | - |
157 | ba.clear(); | - |
158 | quint32 len; | - |
159 | in >> len; | - |
160 | if (len == 0) { evaluated: len == 0 yes Evaluation Count:136 | yes Evaluation Count:180 |
| 136-180 |
161 | ba.clear(); | - |
162 | return in; executed: return in; Execution Count:136 | 136 |
163 | } | - |
164 | | - |
165 | const quint32 Step = 8 * 1024 * 1024; | - |
166 | quint32 totalBytes = (len + 7) / 8; | - |
167 | quint32 allocated = 0; | - |
168 | | - |
169 | while (allocated < totalBytes) { evaluated: allocated < totalBytes yes Evaluation Count:180 | yes Evaluation Count:170 |
| 170-180 |
170 | int blockSize = qMin(Step, totalBytes - allocated); | - |
171 | ba.d.resize(allocated + blockSize + 1); | - |
172 | if (in.readRawData(ba.d.data() + 1 + allocated, blockSize) != blockSize) { evaluated: in.readRawData(ba.d.data() + 1 + allocated, blockSize) != blockSize yes Evaluation Count:10 | yes Evaluation Count:170 |
| 10-170 |
173 | ba.clear(); | - |
174 | in.setStatus(QDataStream::ReadPastEnd); | - |
175 | return in; executed: return in; Execution Count:10 | 10 |
176 | } | - |
177 | allocated += blockSize; | - |
178 | } executed: } Execution Count:170 | 170 |
179 | | - |
180 | int paddingMask = ~((0x1 << (len & 0x7)) - 1); | - |
181 | if (paddingMask != ~0x0 && (ba.d.constData()[ba.d.size() - 1] & paddingMask)) { evaluated: paddingMask != ~0x0 yes Evaluation Count:113 | yes Evaluation Count:57 |
evaluated: (ba.d.constData()[ba.d.size() - 1] & paddingMask) yes Evaluation Count:13 | yes Evaluation Count:100 |
| 13-113 |
182 | ba.clear(); | - |
183 | in.setStatus(QDataStream::ReadCorruptData); | - |
184 | return in; executed: return in; Execution Count:13 | 13 |
185 | } | - |
186 | | - |
187 | *ba.d.data() = ba.d.size() * 8 - len; | - |
188 | return in; executed: return in; Execution Count:157 | 157 |
189 | } | - |
190 | | - |
191 | | - |
192 | | - |
193 | QDebug operator<<(QDebug dbg, const QBitArray &array) | - |
194 | { | - |
195 | dbg.nospace() << "QBitArray("; | - |
196 | for (int i = 0; i < array.size();) { evaluated: i < array.size() yes Evaluation Count:3 | yes Evaluation Count:2 |
| 2-3 |
197 | if (array.testBit(i)) partially evaluated: array.testBit(i) yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
198 | dbg.nospace() << '1'; executed: dbg.nospace() << '1'; Execution Count:3 | 3 |
199 | else | - |
200 | dbg.nospace() << '0'; never executed: dbg.nospace() << '0'; | 0 |
201 | i += 1; | - |
202 | if (!(i % 4) && (i < array.size())) partially evaluated: !(i % 4) no Evaluation Count:0 | yes Evaluation Count:3 |
never evaluated: (i < array.size()) | 0-3 |
203 | dbg.nospace() << ' '; never executed: dbg.nospace() << ' '; | 0 |
204 | } executed: } Execution Count:3 | 3 |
205 | dbg.nospace() << ')'; | - |
206 | return dbg.space(); executed: return dbg.space(); Execution Count:2 | 2 |
207 | } | - |
208 | | - |
209 | | - |
| | |