| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/thread/qresultstore.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qresultstore.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_QFUTURE | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | namespace QtPrivate { | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | ResultIteratorBase::ResultIteratorBase() | - | ||||||||||||||||||
| 49 | : mapIterator(QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { } never executed: end of block | 0 | ||||||||||||||||||
| 50 | ResultIteratorBase::ResultIteratorBase(QMap<int, ResultItem>::const_iterator _mapIterator, int _vectorIndex) | - | ||||||||||||||||||
| 51 | : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { } executed 304147 times by 9 tests: end of blockExecuted by:
| 304147 | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | int ResultIteratorBase::vectorIndex() const { return m_vectorIndex; } never executed: return m_vectorIndex; | 0 | ||||||||||||||||||
| 54 | int ResultIteratorBase::resultIndex() const { return mapIterator.key() + m_vectorIndex; } executed 205 times by 3 tests: return mapIterator.key() + m_vectorIndex;Executed by:
| 205 | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | ResultIteratorBase ResultIteratorBase::operator++() | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 | if (canIncrementVectorIndex()) {
| 215-374 | ||||||||||||||||||
| 59 | ++m_vectorIndex; | - | ||||||||||||||||||
| 60 | } else { executed 215 times by 4 tests: end of blockExecuted by:
| 215 | ||||||||||||||||||
| 61 | ++mapIterator; | - | ||||||||||||||||||
| 62 | m_vectorIndex = 0; | - | ||||||||||||||||||
| 63 | } executed 374 times by 6 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 64 | return *this; executed 589 times by 6 tests: return *this;Executed by:
| 589 | ||||||||||||||||||
| 65 | } | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | int ResultIteratorBase::batchSize() const | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | return mapIterator.value().count(); executed 35102 times by 9 tests: return mapIterator.value().count();Executed by:
| 35102 | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | void ResultIteratorBase::batchedAdvance() | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | ++mapIterator; | - | ||||||||||||||||||
| 75 | m_vectorIndex = 0; | - | ||||||||||||||||||
| 76 | } executed 177 times by 1 test: end of blockExecuted by:
| 177 | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | bool ResultIteratorBase::operator==(const ResultIteratorBase &other) const | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex); executed 114300 times by 9 tests: return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);Executed by:
| 114300 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | return !operator==(other); executed 114279 times by 9 tests: return !operator==(other);Executed by:
| 114279 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | bool ResultIteratorBase::isVector() const | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | return mapIterator.value().isVector(); never executed: return mapIterator.value().isVector(); | 0 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | bool ResultIteratorBase::canIncrementVectorIndex() const | - | ||||||||||||||||||
| 94 | { | - | ||||||||||||||||||
| 95 | return (m_vectorIndex + 1 < mapIterator.value().m_count); executed 589 times by 6 tests: return (m_vectorIndex + 1 < mapIterator.value().m_count);Executed by:
| 589 | ||||||||||||||||||
| 96 | } | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | ResultStoreBase::ResultStoreBase() | - | ||||||||||||||||||
| 99 | : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { } executed 128734 times by 13 tests: end of blockExecuted by:
| 128734 | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | void ResultStoreBase::setFilterMode(bool enable) | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | m_filterMode = enable; | - | ||||||||||||||||||
| 104 | } executed 50 times by 4 tests: end of blockExecuted by:
| 50 | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | bool ResultStoreBase::filterMode() const | - | ||||||||||||||||||
| 107 | { | - | ||||||||||||||||||
| 108 | return m_filterMode; executed 34881 times by 9 tests: return m_filterMode;Executed by:
| 34881 | ||||||||||||||||||
| 109 | } | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | void ResultStoreBase::syncResultCount() | - | ||||||||||||||||||
| 112 | { | - | ||||||||||||||||||
| 113 | ResultIteratorBase it = resultAt(resultCount); | - | ||||||||||||||||||
| 114 | while (it != end()) {
| 34925-34936 | ||||||||||||||||||
| 115 | resultCount += it.batchSize(); | - | ||||||||||||||||||
| 116 | it = resultAt(resultCount); | - | ||||||||||||||||||
| 117 | } executed 34925 times by 9 tests: end of blockExecuted by:
| 34925 | ||||||||||||||||||
| 118 | } executed 34936 times by 9 tests: end of blockExecuted by:
| 34936 | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | void ResultStoreBase::insertResultItemIfValid(int index, ResultItem &resultItem) | - | ||||||||||||||||||
| 121 | { | - | ||||||||||||||||||
| 122 | if (resultItem.isValid()) {
| 229-34936 | ||||||||||||||||||
| 123 | m_results[index] = resultItem; | - | ||||||||||||||||||
| 124 | syncResultCount(); | - | ||||||||||||||||||
| 125 | } else { executed 34936 times by 9 tests: end of blockExecuted by:
| 34936 | ||||||||||||||||||
| 126 | filteredResults += resultItem.count(); | - | ||||||||||||||||||
| 127 | } executed 229 times by 4 tests: end of blockExecuted by:
| 229 | ||||||||||||||||||
| 128 | } | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | int ResultStoreBase::insertResultItem(int index, ResultItem &resultItem) | - | ||||||||||||||||||
| 131 | { | - | ||||||||||||||||||
| 132 | int storeIndex; | - | ||||||||||||||||||
| 133 | if (m_filterMode && index != -1 && index > insertIndex) {
| 0-34676 | ||||||||||||||||||
| 134 | pendingResults[index] = resultItem; | - | ||||||||||||||||||
| 135 | storeIndex = index; | - | ||||||||||||||||||
| 136 | } else { executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 137 | storeIndex = updateInsertIndex(index, resultItem.count()); | - | ||||||||||||||||||
| 138 | insertResultItemIfValid(storeIndex - filteredResults, resultItem); | - | ||||||||||||||||||
| 139 | } executed 35107 times by 9 tests: end of blockExecuted by:
| 35107 | ||||||||||||||||||
| 140 | syncPendingResults(); | - | ||||||||||||||||||
| 141 | return storeIndex; executed 35165 times by 9 tests: return storeIndex;Executed by:
| 35165 | ||||||||||||||||||
| 142 | } | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | void ResultStoreBase::syncPendingResults() | - | ||||||||||||||||||
| 145 | { | - | ||||||||||||||||||
| 146 | // check if we can insert any of the pending results: | - | ||||||||||||||||||
| 147 | QMap<int, ResultItem>::iterator it = pendingResults.begin(); | - | ||||||||||||||||||
| 148 | while (it != pendingResults.end()) {
| 102-35121 | ||||||||||||||||||
| 149 | int index = it.key(); | - | ||||||||||||||||||
| 150 | if (index != resultCount + filteredResults)
| 44-58 | ||||||||||||||||||
| 151 | break; executed 44 times by 2 tests: break;Executed by:
| 44 | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | ResultItem result = it.value(); | - | ||||||||||||||||||
| 154 | insertResultItemIfValid(index - filteredResults, result); | - | ||||||||||||||||||
| 155 | pendingResults.erase(it); | - | ||||||||||||||||||
| 156 | it = pendingResults.begin(); | - | ||||||||||||||||||
| 157 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 158 | } executed 35165 times by 9 tests: end of blockExecuted by:
| 35165 | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | int ResultStoreBase::addResult(int index, const void *result) | - | ||||||||||||||||||
| 161 | { | - | ||||||||||||||||||
| 162 | ResultItem resultItem(result, 0); // 0 means "not a vector" | - | ||||||||||||||||||
| 163 | return insertResultItem(index, resultItem); executed 34625 times by 9 tests: return insertResultItem(index, resultItem);Executed by:
| 34625 | ||||||||||||||||||
| 164 | } | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount) | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | if (m_filterMode == false || vectorSize == totalCount) {
| 49-231 | ||||||||||||||||||
| 169 | ResultItem resultItem(results, vectorSize); | - | ||||||||||||||||||
| 170 | return insertResultItem(index, resultItem); executed 222 times by 5 tests: return insertResultItem(index, resultItem);Executed by:
| 222 | ||||||||||||||||||
| 171 | } else { | - | ||||||||||||||||||
| 172 | if (vectorSize > 0) {
| 46-136 | ||||||||||||||||||
| 173 | ResultItem filteredIn(results, vectorSize); | - | ||||||||||||||||||
| 174 | insertResultItem(index, filteredIn); | - | ||||||||||||||||||
| 175 | } executed 136 times by 2 tests: end of blockExecuted by:
| 136 | ||||||||||||||||||
| 176 | ResultItem filteredAway(0, totalCount - vectorSize); | - | ||||||||||||||||||
| 177 | return insertResultItem(index + vectorSize, filteredAway); executed 182 times by 4 tests: return insertResultItem(index + vectorSize, filteredAway);Executed by:
| 182 | ||||||||||||||||||
| 178 | } | - | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | ResultIteratorBase ResultStoreBase::begin() const | - | ||||||||||||||||||
| 182 | { | - | ||||||||||||||||||
| 183 | return ResultIteratorBase(m_results.begin()); executed 147 times by 7 tests: return ResultIteratorBase(m_results.begin());Executed by:
| 147 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | ResultIteratorBase ResultStoreBase::end() const | - | ||||||||||||||||||
| 187 | { | - | ||||||||||||||||||
| 188 | return ResultIteratorBase(m_results.end()); executed 114284 times by 9 tests: return ResultIteratorBase(m_results.end());Executed by:
| 114284 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | bool ResultStoreBase::hasNextResult() const | - | ||||||||||||||||||
| 192 | { | - | ||||||||||||||||||
| 193 | return begin() != end(); never executed: return begin() != end(); | 0 | ||||||||||||||||||
| 194 | } | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | ResultIteratorBase ResultStoreBase::resultAt(int index) const | - | ||||||||||||||||||
| 197 | { | - | ||||||||||||||||||
| 198 | if (m_results.isEmpty())
| 252-189464 | ||||||||||||||||||
| 199 | return ResultIteratorBase(m_results.end()); executed 252 times by 8 tests: return ResultIteratorBase(m_results.end());Executed by:
| 252 | ||||||||||||||||||
| 200 | QMap<int, ResultItem>::const_iterator it = m_results.lowerBound(index); | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | // lowerBound returns either an iterator to the result or an iterator | - | ||||||||||||||||||
| 203 | // to the nearest greater index. If the latter happens it might be | - | ||||||||||||||||||
| 204 | // that the result is stored in a vector at the previous index. | - | ||||||||||||||||||
| 205 | if (it == m_results.end()) {
| 42340-147124 | ||||||||||||||||||
| 206 | --it; | - | ||||||||||||||||||
| 207 | if (it.value().isVector() == false) {
| 7529-34811 | ||||||||||||||||||
| 208 | return ResultIteratorBase(m_results.end()); executed 34811 times by 9 tests: return ResultIteratorBase(m_results.end());Executed by:
| 34811 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | } else { executed 7529 times by 5 tests: end of blockExecuted by:
| 7529 | ||||||||||||||||||
| 211 | if (it.key() > index) {
| 51615-95509 | ||||||||||||||||||
| 212 | if (it == m_results.begin())
| 24-51591 | ||||||||||||||||||
| 213 | return ResultIteratorBase(m_results.end()); executed 24 times by 2 tests: return ResultIteratorBase(m_results.end());Executed by:
| 24 | ||||||||||||||||||
| 214 | --it; | - | ||||||||||||||||||
| 215 | } executed 51591 times by 5 tests: end of blockExecuted by:
| 51591 | ||||||||||||||||||
| 216 | } executed 147100 times by 9 tests: end of blockExecuted by:
| 147100 | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | const int vectorIndex = index - it.key(); | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | if (vectorIndex >= it.value().count())
| 401-154228 | ||||||||||||||||||
| 221 | return ResultIteratorBase(m_results.end()); executed 401 times by 5 tests: return ResultIteratorBase(m_results.end());Executed by:
| 401 | ||||||||||||||||||
| 222 | else if (it.value().isVector() == false && vectorIndex != 0)
| 0-84682 | ||||||||||||||||||
| 223 | return ResultIteratorBase(m_results.end()); never executed: return ResultIteratorBase(m_results.end()); | 0 | ||||||||||||||||||
| 224 | return ResultIteratorBase(it, vectorIndex); executed 154228 times by 9 tests: return ResultIteratorBase(it, vectorIndex);Executed by:
| 154228 | ||||||||||||||||||
| 225 | } | - | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | bool ResultStoreBase::contains(int index) const | - | ||||||||||||||||||
| 228 | { | - | ||||||||||||||||||
| 229 | return (resultAt(index) != end()); executed 43525 times by 9 tests: return (resultAt(index) != end());Executed by:
| 43525 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | int ResultStoreBase::count() const | - | ||||||||||||||||||
| 233 | { | - | ||||||||||||||||||
| 234 | return resultCount; executed 29310 times by 5 tests: return resultCount;Executed by:
| 29310 | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | // returns the insert index, calling this function with | - | ||||||||||||||||||
| 238 | // index equal to -1 returns the next available index. | - | ||||||||||||||||||
| 239 | int ResultStoreBase::updateInsertIndex(int index, int _count) | - | ||||||||||||||||||
| 240 | { | - | ||||||||||||||||||
| 241 | if (index == -1) {
| 1068-34039 | ||||||||||||||||||
| 242 | index = insertIndex; | - | ||||||||||||||||||
| 243 | insertIndex += _count; | - | ||||||||||||||||||
| 244 | } else { executed 34039 times by 8 tests: end of blockExecuted by:
| 34039 | ||||||||||||||||||
| 245 | insertIndex = qMax(index + _count, insertIndex); | - | ||||||||||||||||||
| 246 | } executed 1068 times by 6 tests: end of blockExecuted by:
| 1068 | ||||||||||||||||||
| 247 | return index; executed 35107 times by 9 tests: return index;Executed by:
| 35107 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | } // namespace QtPrivate | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 253 | - | |||||||||||||||||||
| 254 | #endif // QT_NO_QFUTURE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |