| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qversionnumber.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | - | |||||||
| 10 | - | |||||||
| 11 | - | |||||||
| 12 | QVector<int> QVersionNumber::segments() const | - | ||||||
| 13 | { | - | ||||||
| 14 | if (m_segments.isUsingPointer()) | - | ||||||
| 15 | return *m_segments.pointer_segments; | - | ||||||
| 16 | - | |||||||
| 17 | QVector<int> result; | - | ||||||
| 18 | result.resize(segmentCount()); | - | ||||||
| 19 | for (int i = 0; i < segmentCount(); ++i) | - | ||||||
| 20 | result[i] = segmentAt(i); | - | ||||||
| 21 | return result; | - | ||||||
| 22 | } | - | ||||||
| 23 | QVersionNumber QVersionNumber::normalized() const | - | ||||||
| 24 | { | - | ||||||
| 25 | int i; | - | ||||||
| 26 | for (i = m_segments.size(); i; --i) | - | ||||||
| 27 | if (m_segments.at(i - 1) != 0) | - | ||||||
| 28 | break; | - | ||||||
| 29 | - | |||||||
| 30 | QVersionNumber result(*this); | - | ||||||
| 31 | result.m_segments.resize(i); | - | ||||||
| 32 | return result; | - | ||||||
| 33 | } | - | ||||||
| 34 | bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const noexcept | - | ||||||
| 35 | { | - | ||||||
| 36 | if (segmentCount() > other.segmentCount()
| 10-41 | ||||||
| 37 | return executed 10 times by 1 test: false;return false;Executed by:
executed 10 times by 1 test: return false;Executed by:
| 10 | ||||||
| 38 | for (int i = 0; i < segmentCount()
| 17-123 | ||||||
| 39 | if (segmentAt(i) != other.segmentAt(i)
| 24-99 | ||||||
| 40 | return executed 24 times by 1 test: false;return false;Executed by:
executed 24 times by 1 test: return false;Executed by:
| 24 | ||||||
| 41 | } executed 99 times by 1 test: end of blockExecuted by:
| 99 | ||||||
| 42 | return executed 17 times by 1 test: true;return true;Executed by:
executed 17 times by 1 test: return true;Executed by:
| 17 | ||||||
| 43 | } | - | ||||||
| 44 | int QVersionNumber::compare(const QVersionNumber &v1, const QVersionNumber &v2) noexcept | - | ||||||
| 45 | { | - | ||||||
| 46 | int commonlen; | - | ||||||
| 47 | - | |||||||
| 48 | if (__builtin_expect(!!(!v1.m_segments.isUsingPointer() && !v2.m_segments.isUsingPointer()), true)
| 190-324 | ||||||
| 49 | - | |||||||
| 50 | const qint8 *ptr1 = v1.m_segments.inline_segments + InlineSegmentStartIdx; | - | ||||||
| 51 | const qint8 *ptr2 = v2.m_segments.inline_segments + InlineSegmentStartIdx; | - | ||||||
| 52 | commonlen = qMin(v1.m_segments.size(), | - | ||||||
| 53 | v2.m_segments.size()); | - | ||||||
| 54 | for (int i = 0; i < commonlen
| 237-498 | ||||||
| 55 | if (int x = ptr1[i] - ptr2[i]
| 87-411 | ||||||
| 56 | return executed 87 times by 2 tests: x;return x;Executed by:
executed 87 times by 2 tests: return x;Executed by:
| 87 | ||||||
| 57 | } executed 237 times by 1 test: else {end of blockExecuted by:
| 237 | ||||||
| 58 | commonlen = qMin(v1.segmentCount(), v2.segmentCount()); | - | ||||||
| 59 | for (int i = 0; i < commonlen
| 104-997 | ||||||
| 60 | if (v1.segmentAt(i) != v2.segmentAt(i)
| 86-911 | ||||||
| 61 | return executed 86 times by 2 tests: v1.segmentAt(i) - v2.segmentAt(i);return v1.segmentAt(i) - v2.segmentAt(i);Executed by:
executed 86 times by 2 tests: return v1.segmentAt(i) - v2.segmentAt(i);Executed by:
| 86 | ||||||
| 62 | } executed 911 times by 2 tests: end of blockExecuted by:
| 911 | ||||||
| 63 | } executed 104 times by 1 test: end of blockExecuted by:
| 104 | ||||||
| 64 | - | |||||||
| 65 | - | |||||||
| 66 | - | |||||||
| 67 | if (v1.segmentCount() > commonlen
| 70-271 | ||||||
| 68 | - | |||||||
| 69 | if (v1.segmentAt(commonlen) != 0
| 14-56 | ||||||
| 70 | return executed 56 times by 1 test: v1.segmentAt(commonlen);return v1.segmentAt(commonlen);Executed by:
executed 56 times by 1 test: return v1.segmentAt(commonlen);Executed by:
| 56 | ||||||
| 71 | else | - | ||||||
| 72 | return executed 14 times by 1 test: 1;return 1;Executed by:
executed 14 times by 1 test: return 1;Executed by:
| 14 | ||||||
| 73 | } else if (v2.segmentCount() > commonlen
| 70-201 | ||||||
| 74 | - | |||||||
| 75 | if (v2.segmentAt(commonlen) != 0
| 14-56 | ||||||
| 76 | return executed 56 times by 1 test: -v2.segmentAt(commonlen);return -v2.segmentAt(commonlen);Executed by:
executed 56 times by 1 test: return -v2.segmentAt(commonlen);Executed by:
| 56 | ||||||
| 77 | else | - | ||||||
| 78 | return executed 14 times by 1 test: -1;return -1;Executed by:
executed 14 times by 1 test: return -1;Executed by:
| 14 | ||||||
| 79 | } | - | ||||||
| 80 | - | |||||||
| 81 | - | |||||||
| 82 | return executed 201 times by 1 test: 0;return 0;Executed by:
executed 201 times by 1 test: return 0;Executed by:
| 201 | ||||||
| 83 | } | - | ||||||
| 84 | QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &v1, | - | ||||||
| 85 | const QVersionNumber &v2) | - | ||||||
| 86 | { | - | ||||||
| 87 | int commonlen = qMin(v1.segmentCount(), v2.segmentCount()); | - | ||||||
| 88 | int i; | - | ||||||
| 89 | for (i = 0; i < commonlen; ++i) { | - | ||||||
| 90 | if (v1.segmentAt(i) != v2.segmentAt(i)) | - | ||||||
| 91 | break; | - | ||||||
| 92 | } | - | ||||||
| 93 | - | |||||||
| 94 | if (i == 0) | - | ||||||
| 95 | return QVersionNumber(); | - | ||||||
| 96 | - | |||||||
| 97 | - | |||||||
| 98 | QVersionNumber result(!v1.m_segments.isUsingPointer() ? v1 : v2); | - | ||||||
| 99 | result.m_segments.resize(i); | - | ||||||
| 100 | return result; | - | ||||||
| 101 | } | - | ||||||
| 102 | QString QVersionNumber::toString() const | - | ||||||
| 103 | { | - | ||||||
| 104 | QString version; | - | ||||||
| 105 | version.reserve(qMax(segmentCount() * 2 - 1, 0)); | - | ||||||
| 106 | bool first = true; | - | ||||||
| 107 | for (int i = 0; i < segmentCount(); ++i) { | - | ||||||
| 108 | if (!first) | - | ||||||
| 109 | version += QLatin1Char('.'); | - | ||||||
| 110 | version += QString::number(segmentAt(i)); | - | ||||||
| 111 | first = false; | - | ||||||
| 112 | } | - | ||||||
| 113 | return version; | - | ||||||
| 114 | } | - | ||||||
| 115 | QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixIndex) | - | ||||||
| 116 | { | - | ||||||
| 117 | QVector<int> seg; | - | ||||||
| 118 | - | |||||||
| 119 | const QByteArray cString(string.toLatin1()); | - | ||||||
| 120 | - | |||||||
| 121 | const char *start = cString.constData(); | - | ||||||
| 122 | const char *end = start; | - | ||||||
| 123 | const char *lastGoodEnd = start; | - | ||||||
| 124 | const char *endOfString = cString.constData() + cString.size(); | - | ||||||
| 125 | - | |||||||
| 126 | do { | - | ||||||
| 127 | bool ok = false; | - | ||||||
| 128 | const qulonglong value = qstrtoull(start, &end, 10, &ok); | - | ||||||
| 129 | if (!ok || value > qulonglong(std::numeric_limits<int>::max())) | - | ||||||
| 130 | break; | - | ||||||
| 131 | seg.append(int(value)); | - | ||||||
| 132 | start = end + 1; | - | ||||||
| 133 | lastGoodEnd = end; | - | ||||||
| 134 | } while (start < endOfString && (end < endOfString && *end == '.')); | - | ||||||
| 135 | - | |||||||
| 136 | if (suffixIndex) | - | ||||||
| 137 | *suffixIndex = int(lastGoodEnd - cString.constData()); | - | ||||||
| 138 | - | |||||||
| 139 | return QVersionNumber(std::move(seg)); | - | ||||||
| 140 | } | - | ||||||
| 141 | - | |||||||
| 142 | void QVersionNumber::SegmentStorage::setVector(int len, int maj, int min, int mic) | - | ||||||
| 143 | { | - | ||||||
| 144 | pointer_segments = new QVector<int>; | - | ||||||
| 145 | pointer_segments->resize(len); | - | ||||||
| 146 | pointer_segments->data()[0] = maj; | - | ||||||
| 147 | if (len > 1) { | - | ||||||
| 148 | pointer_segments->data()[1] = min; | - | ||||||
| 149 | if (len > 2) { | - | ||||||
| 150 | pointer_segments->data()[2] = mic; | - | ||||||
| 151 | } | - | ||||||
| 152 | } | - | ||||||
| 153 | } | - | ||||||
| 154 | QDataStream& operator<<(QDataStream &out, const QVersionNumber &version) | - | ||||||
| 155 | { | - | ||||||
| 156 | out << version.segments(); | - | ||||||
| 157 | return out; | - | ||||||
| 158 | } | - | ||||||
| 159 | QDataStream& operator>>(QDataStream &in, QVersionNumber &version) | - | ||||||
| 160 | { | - | ||||||
| 161 | if (!version.m_segments.isUsingPointer()) | - | ||||||
| 162 | version.m_segments.pointer_segments = new QVector<int>; | - | ||||||
| 163 | in >> *version.m_segments.pointer_segments; | - | ||||||
| 164 | return in; | - | ||||||
| 165 | } | - | ||||||
| 166 | - | |||||||
| 167 | - | |||||||
| 168 | - | |||||||
| 169 | QDebug operator<<(QDebug debug, const QVersionNumber &version) | - | ||||||
| 170 | { | - | ||||||
| 171 | QDebugStateSaver saver(debug); | - | ||||||
| 172 | debug.noquote() << version.toString(); | - | ||||||
| 173 | return debug; | - | ||||||
| 174 | } | - | ||||||
| 175 | uint qHash(const QVersionNumber &key, uint seed) | - | ||||||
| 176 | { | - | ||||||
| 177 | QtPrivate::QHashCombine hash; | - | ||||||
| 178 | for (int i = 0; i < key.segmentCount(); ++i) | - | ||||||
| 179 | seed = hash(seed, key.segmentAt(i)); | - | ||||||
| 180 | return seed; | - | ||||||
| 181 | } | - | ||||||
| 182 | - | |||||||
| 183 | - | |||||||
| Switch to Source code | Preprocessed file |