| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qbitarray.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | QBitArray::QBitArray(int size, bool value) | - | ||||||||||||||||||
| 5 | : d(size <= 0 ? 0 : 1 + (size + 7)/8, Qt::Uninitialized) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | ((!(size >= 0)) ? qt_assert_x("QBitArray::QBitArray", "Size must be greater than or equal to 0.",__FILE__,143) : qt_noop()); | - | ||||||||||||||||||
| 8 | if (size <= 0
| 303-16972 | ||||||||||||||||||
| 9 | return; executed 303 times by 6 tests: return;Executed by:
| 303 | ||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
| 12 | memset(c + 1, value ? 0xff : 0, d.size() - 1); | - | ||||||||||||||||||
| 13 | *c = d.size()*8 - size; | - | ||||||||||||||||||
| 14 | if (value
| 0-12933 | ||||||||||||||||||
| 15 | *( executed 3532 times by 4 tests: c+1+size/8) &= (1 << (size%8)) - 1;*(c+1+size/8) &= (1 << (size%8)) - 1;Executed by:
executed 3532 times by 4 tests: *(c+1+size/8) &= (1 << (size%8)) - 1;Executed by:
| 3532 | ||||||||||||||||||
| 16 | } executed 16972 times by 29 tests: end of blockExecuted by:
| 16972 | ||||||||||||||||||
| 17 | int QBitArray::count(bool on) const | - | ||||||||||||||||||
| 18 | { | - | ||||||||||||||||||
| 19 | int numBits = 0; | - | ||||||||||||||||||
| 20 | const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1; | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | const quint8 *const end = reinterpret_cast<const quint8 *>(d.end()); | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | while (bits + 7 <= end
| 16147-499980 | ||||||||||||||||||
| 27 | quint64 v = qFromUnaligned<quint64>(bits); | - | ||||||||||||||||||
| 28 | bits += 8; | - | ||||||||||||||||||
| 29 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
| 30 | } executed 499980 times by 1 test: end of blockExecuted by:
| 499980 | ||||||||||||||||||
| 31 | if (bits + 3 <= end
| 8041-8106 | ||||||||||||||||||
| 32 | quint32 v = qFromUnaligned<quint32>(bits); | - | ||||||||||||||||||
| 33 | bits += 4; | - | ||||||||||||||||||
| 34 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
| 35 | } executed 8106 times by 1 test: end of blockExecuted by:
| 8106 | ||||||||||||||||||
| 36 | if (bits + 1 < end
| 4038-12109 | ||||||||||||||||||
| 37 | quint16 v = qFromUnaligned<quint16>(bits); | - | ||||||||||||||||||
| 38 | bits += 2; | - | ||||||||||||||||||
| 39 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
| 40 | } executed 4038 times by 1 test: end of blockExecuted by:
| 4038 | ||||||||||||||||||
| 41 | if (bits < end
| 4069-12078 | ||||||||||||||||||
| 42 | numBits += int(qPopulationCount(bits[0])); executed 4069 times by 2 tests: numBits += int(qPopulationCount(bits[0]));Executed by:
| 4069 | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | return executed 16147 times by 2 tests: onreturn on ? numBits : size() - numBits;Executed by:
executed 16147 times by 2 tests: return on ? numBits : size() - numBits;Executed by:
| 8073-16147 | ||||||||||||||||||
| 45 | } | - | ||||||||||||||||||
| 46 | void QBitArray::resize(int size) | - | ||||||||||||||||||
| 47 | { | - | ||||||||||||||||||
| 48 | if (!size
| 52-4482 | ||||||||||||||||||
| 49 | d.resize(0); | - | ||||||||||||||||||
| 50 | } executed 52 times by 3 tests: else {end of blockExecuted by:
| 52 | ||||||||||||||||||
| 51 | int s = d.size(); | - | ||||||||||||||||||
| 52 | d.resize(1 + (size+7)/8); | - | ||||||||||||||||||
| 53 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
| 54 | if (size > (s << 3)
| 405-4077 | ||||||||||||||||||
| 55 | memset(c + s, 0, d.size() - s); executed 405 times by 10 tests: memset(c + s, 0, d.size() - s);Executed by:
| 405 | ||||||||||||||||||
| 56 | else if ( size % 8
| 514-3563 | ||||||||||||||||||
| 57 | *( executed 3563 times by 7 tests: c+1+size/8) &= (1 << (size%8)) - 1;*(c+1+size/8) &= (1 << (size%8)) - 1;Executed by:
executed 3563 times by 7 tests: *(c+1+size/8) &= (1 << (size%8)) - 1;Executed by:
| 3563 | ||||||||||||||||||
| 58 | *c = d.size()*8 - size; | - | ||||||||||||||||||
| 59 | } executed 4482 times by 11 tests: end of blockExecuted by:
| 4482 | ||||||||||||||||||
| 60 | } | - | ||||||||||||||||||
| 61 | void QBitArray::fill(bool value, int begin, int end) | - | ||||||||||||||||||
| 62 | { | - | ||||||||||||||||||
| 63 | while (begin < end
| 56-492 | ||||||||||||||||||
| 64 | setBit(begin++, value); executed 390 times by 1 test: setBit(begin++, value);Executed by:
| 390 | ||||||||||||||||||
| 65 | int len = end - begin; | - | ||||||||||||||||||
| 66 | if (len <= 0
| 56-102 | ||||||||||||||||||
| 67 | return; executed 56 times by 1 test: return;Executed by:
| 56 | ||||||||||||||||||
| 68 | int s = len & ~0x7; | - | ||||||||||||||||||
| 69 | uchar *c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
| 70 | memset(c + (begin >> 3) + 1, value ? 0xff : 0, s >> 3); | - | ||||||||||||||||||
| 71 | begin += s; | - | ||||||||||||||||||
| 72 | while (begin < end
| 102-344 | ||||||||||||||||||
| 73 | setBit(begin++, value); executed 344 times by 1 test: setBit(begin++, value);Executed by:
| 344 | ||||||||||||||||||
| 74 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 75 | QBitArray &QBitArray::operator&=(const QBitArray &other) | - | ||||||||||||||||||
| 76 | { | - | ||||||||||||||||||
| 77 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
| 78 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
| 79 | const uchar *a2 = reinterpret_cast<const uchar*>(other.d.constData()) + 1; | - | ||||||||||||||||||
| 80 | int n = other.d.size() -1 ; | - | ||||||||||||||||||
| 81 | int p = d.size() - 1 - n; | - | ||||||||||||||||||
| 82 | while (n-- > 0
| 8-9 | ||||||||||||||||||
| 83 | * executed 9 times by 1 test: a1++ &= *a2++;*a1++ &= *a2++;Executed by:
executed 9 times by 1 test: *a1++ &= *a2++;Executed by:
| 9 | ||||||||||||||||||
| 84 | while (p-- > 0
| 4-8 | ||||||||||||||||||
| 85 | * executed 4 times by 1 test: a1++ = 0;*a1++ = 0;Executed by:
executed 4 times by 1 test: *a1++ = 0;Executed by:
| 4 | ||||||||||||||||||
| 86 | return executed 8 times by 1 test: *this;return *this;Executed by:
executed 8 times by 1 test: return *this;Executed by:
| 8 | ||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | QBitArray &QBitArray::operator|=(const QBitArray &other) | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
| 91 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
| 92 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - | ||||||||||||||||||
| 93 | int n = other.d.size() - 1; | - | ||||||||||||||||||
| 94 | while (n-- > 0
| 8 | ||||||||||||||||||
| 95 | * executed 8 times by 1 test: a1++ |= *a2++;*a1++ |= *a2++;Executed by:
executed 8 times by 1 test: *a1++ |= *a2++;Executed by:
| 8 | ||||||||||||||||||
| 96 | return executed 8 times by 1 test: *this;return *this;Executed by:
executed 8 times by 1 test: return *this;Executed by:
| 8 | ||||||||||||||||||
| 97 | } | - | ||||||||||||||||||
| 98 | QBitArray &QBitArray::operator^=(const QBitArray &other) | - | ||||||||||||||||||
| 99 | { | - | ||||||||||||||||||
| 100 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
| 101 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
| 102 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - | ||||||||||||||||||
| 103 | int n = other.d.size() - 1; | - | ||||||||||||||||||
| 104 | while (n-- > 0
| 8-9 | ||||||||||||||||||
| 105 | * executed 9 times by 1 test: a1++ ^= *a2++;*a1++ ^= *a2++;Executed by:
executed 9 times by 1 test: *a1++ ^= *a2++;Executed by:
| 9 | ||||||||||||||||||
| 106 | return executed 8 times by 1 test: *this;return *this;Executed by:
executed 8 times by 1 test: return *this;Executed by:
| 8 | ||||||||||||||||||
| 107 | } | - | ||||||||||||||||||
| 108 | QBitArray QBitArray::operator~() const | - | ||||||||||||||||||
| 109 | { | - | ||||||||||||||||||
| 110 | int sz = size(); | - | ||||||||||||||||||
| 111 | QBitArray a(sz); | - | ||||||||||||||||||
| 112 | const uchar *a1 = reinterpret_cast<const uchar *>(d.constData()) + 1; | - | ||||||||||||||||||
| 113 | uchar *a2 = reinterpret_cast<uchar*>(a.d.data()) + 1; | - | ||||||||||||||||||
| 114 | int n = d.size() - 1; | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | while (n-- > 0
| 13 | ||||||||||||||||||
| 117 | * executed 13 times by 2 tests: a2++ = ~*a1++;*a2++ = ~*a1++;Executed by:
executed 13 times by 2 tests: *a2++ = ~*a1++;Executed by:
| 13 | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | if (sz
| 2-11 | ||||||||||||||||||
| 120 | *( executed 6 times by 2 tests: a2-1) &= (1 << (sz%8)) - 1;*(a2-1) &= (1 << (sz%8)) - 1;Executed by:
executed 6 times by 2 tests: *(a2-1) &= (1 << (sz%8)) - 1;Executed by:
| 6 | ||||||||||||||||||
| 121 | return executed 13 times by 2 tests: a;return a;Executed by:
executed 13 times by 2 tests: return a;Executed by:
| 13 | ||||||||||||||||||
| 122 | } | - | ||||||||||||||||||
| 123 | QBitArray operator&(const QBitArray &a1, const QBitArray &a2) | - | ||||||||||||||||||
| 124 | { | - | ||||||||||||||||||
| 125 | QBitArray tmp = a1; | - | ||||||||||||||||||
| 126 | tmp &= a2; | - | ||||||||||||||||||
| 127 | return never executed: tmp;return tmp;never executed: return tmp; | 0 | ||||||||||||||||||
| 128 | } | - | ||||||||||||||||||
| 129 | QBitArray operator|(const QBitArray &a1, const QBitArray &a2) | - | ||||||||||||||||||
| 130 | { | - | ||||||||||||||||||
| 131 | QBitArray tmp = a1; | - | ||||||||||||||||||
| 132 | tmp |= a2; | - | ||||||||||||||||||
| 133 | return never executed: tmp;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 never executed: tmp;return tmp;never executed: return tmp; | 0 | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | QDataStream &operator<<(QDataStream &out, const QBitArray &ba) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | quint32 len = ba.size(); | - | ||||||||||||||||||
| 144 | out << len; | - | ||||||||||||||||||
| 145 | if (len > 0
| 140-256 | ||||||||||||||||||
| 146 | out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1); executed 140 times by 4 tests: out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1);Executed by:
| 140 | ||||||||||||||||||
| 147 | return executed 396 times by 9 tests: out;return out;Executed by:
executed 396 times by 9 tests: return out;Executed by:
| 396 | ||||||||||||||||||
| 148 | } | - | ||||||||||||||||||
| 149 | QDataStream &operator>>(QDataStream &in, QBitArray &ba) | - | ||||||||||||||||||
| 150 | { | - | ||||||||||||||||||
| 151 | ba.clear(); | - | ||||||||||||||||||
| 152 | quint32 len; | - | ||||||||||||||||||
| 153 | in >> len; | - | ||||||||||||||||||
| 154 | if (len == 0
| 181-284 | ||||||||||||||||||
| 155 | ba.clear(); | - | ||||||||||||||||||
| 156 | return executed 284 times by 9 tests: in;return in;Executed by:
executed 284 times by 9 tests: return in;Executed by:
| 284 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | const quint32 Step = 8 * 1024 * 1024; | - | ||||||||||||||||||
| 160 | quint32 totalBytes = (len + 7) / 8; | - | ||||||||||||||||||
| 161 | quint32 allocated = 0; | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | while (allocated < totalBytes
| 171-181 | ||||||||||||||||||
| 164 | int blockSize = qMin(Step, totalBytes - allocated); | - | ||||||||||||||||||
| 165 | ba.d.resize(allocated + blockSize + 1); | - | ||||||||||||||||||
| 166 | if (in.readRawData(ba.d.data() + 1 + allocated, blockSize) != blockSize
| 10-171 | ||||||||||||||||||
| 167 | ba.clear(); | - | ||||||||||||||||||
| 168 | in.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||||||||
| 169 | return executed 10 times by 1 test: in;return in;Executed by:
executed 10 times by 1 test: return in;Executed by:
| 10 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | allocated += blockSize; | - | ||||||||||||||||||
| 172 | } executed 171 times by 4 tests: end of blockExecuted by:
| 171 | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | int paddingMask = ~((0x1 << (len & 0x7)) - 1); | - | ||||||||||||||||||
| 175 | if (paddingMask != ~0x0
| 13-114 | ||||||||||||||||||
| 176 | ba.clear(); | - | ||||||||||||||||||
| 177 | in.setStatus(QDataStream::ReadCorruptData); | - | ||||||||||||||||||
| 178 | return executed 13 times by 1 test: in;return in;Executed by:
executed 13 times by 1 test: return in;Executed by:
| 13 | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | *ba.d.data() = ba.d.size() * 8 - len; | - | ||||||||||||||||||
| 182 | return executed 158 times by 4 tests: in;return in;Executed by:
executed 158 times by 4 tests: return in;Executed by:
| 158 | ||||||||||||||||||
| 183 | } | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | QDebug operator<<(QDebug dbg, const QBitArray &array) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 190 | dbg.nospace() << "QBitArray("; | - | ||||||||||||||||||
| 191 | for (int i = 0; i < array.size()
| 2-3 | ||||||||||||||||||
| 192 | if (array.testBit(i)
| 0-3 | ||||||||||||||||||
| 193 | dbg << '1'; executed 3 times by 1 test: dbg << '1';Executed by:
| 3 | ||||||||||||||||||
| 194 | else | - | ||||||||||||||||||
| 195 | dbg << '0'; never executed: dbg << '0'; | 0 | ||||||||||||||||||
| 196 | i += 1; | - | ||||||||||||||||||
| 197 | if (!(i % 4)
| 0-3 | ||||||||||||||||||
| 198 | dbg << ' '; never executed: dbg << ' '; | 0 | ||||||||||||||||||
| 199 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 200 | dbg << ')'; | - | ||||||||||||||||||
| 201 | return executed 2 times by 1 test: dbg;return dbg;Executed by:
executed 2 times by 1 test: return dbg;Executed by:
| 2 | ||||||||||||||||||
| 202 | } | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |