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) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qresultstore.h" | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #ifndef QT_NO_QFUTURE | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | namespace QtPrivate { | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | ResultIteratorBase::ResultIteratorBase() | - | ||||||||||||||||||
43 | : mapIterator(QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { } never executed: end of block | 0 | ||||||||||||||||||
44 | ResultIteratorBase::ResultIteratorBase(QMap<int, ResultItem>::const_iterator _mapIterator, int _vectorIndex) | - | ||||||||||||||||||
45 | : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { } executed 304718 times by 9 tests: end of block Executed by:
| 304718 | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | int ResultIteratorBase::vectorIndex() const { return m_vectorIndex; } never executed: return m_vectorIndex; | 0 | ||||||||||||||||||
48 | int ResultIteratorBase::resultIndex() const { return mapIterator.key() + m_vectorIndex; } executed 205 times by 3 tests: return mapIterator.key() + m_vectorIndex; Executed by:
| 205 | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | ResultIteratorBase ResultIteratorBase::operator++() | - | ||||||||||||||||||
51 | { | - | ||||||||||||||||||
52 | if (canIncrementVectorIndex()) {
| 215-374 | ||||||||||||||||||
53 | ++m_vectorIndex; | - | ||||||||||||||||||
54 | } else { executed 215 times by 4 tests: end of block Executed by:
| 215 | ||||||||||||||||||
55 | ++mapIterator; | - | ||||||||||||||||||
56 | m_vectorIndex = 0; | - | ||||||||||||||||||
57 | } executed 374 times by 6 tests: end of block Executed by:
| 374 | ||||||||||||||||||
58 | return *this; executed 589 times by 6 tests: return *this; Executed by:
| 589 | ||||||||||||||||||
59 | } | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | int ResultIteratorBase::batchSize() const | - | ||||||||||||||||||
62 | { | - | ||||||||||||||||||
63 | return mapIterator.value().count(); executed 35102 times by 9 tests: return mapIterator.value().count(); Executed by:
| 35102 | ||||||||||||||||||
64 | } | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | void ResultIteratorBase::batchedAdvance() | - | ||||||||||||||||||
67 | { | - | ||||||||||||||||||
68 | ++mapIterator; | - | ||||||||||||||||||
69 | m_vectorIndex = 0; | - | ||||||||||||||||||
70 | } executed 177 times by 1 test: end of block Executed by:
| 177 | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | bool ResultIteratorBase::operator==(const ResultIteratorBase &other) const | - | ||||||||||||||||||
73 | { | - | ||||||||||||||||||
74 | return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex); executed 113311 times by 9 tests: return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex); Executed by:
| 2-113311 | ||||||||||||||||||
75 | } | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const | - | ||||||||||||||||||
78 | { | - | ||||||||||||||||||
79 | return !operator==(other); executed 114466 times by 9 tests: return !operator==(other); Executed by:
| 114466 | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | bool ResultIteratorBase::isVector() const | - | ||||||||||||||||||
83 | { | - | ||||||||||||||||||
84 | return mapIterator.value().isVector(); never executed: return mapIterator.value().isVector(); | 0 | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | bool ResultIteratorBase::canIncrementVectorIndex() const | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | 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 | ||||||||||||||||||
90 | } | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | ResultStoreBase::ResultStoreBase() | - | ||||||||||||||||||
93 | : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { } executed 128717 times by 13 tests: end of block Executed by:
| 128717 | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | void ResultStoreBase::setFilterMode(bool enable) | - | ||||||||||||||||||
96 | { | - | ||||||||||||||||||
97 | m_filterMode = enable; | - | ||||||||||||||||||
98 | } executed 50 times by 4 tests: end of block Executed by:
| 50 | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | bool ResultStoreBase::filterMode() const | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | return m_filterMode; executed 34881 times by 9 tests: return m_filterMode; Executed by:
| 34881 | ||||||||||||||||||
103 | } | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | void ResultStoreBase::syncResultCount() | - | ||||||||||||||||||
106 | { | - | ||||||||||||||||||
107 | ResultIteratorBase it = resultAt(resultCount); | - | ||||||||||||||||||
108 | while (it != end()) {
| 34925-34936 | ||||||||||||||||||
109 | resultCount += it.batchSize(); | - | ||||||||||||||||||
110 | it = resultAt(resultCount); | - | ||||||||||||||||||
111 | } executed 34925 times by 9 tests: end of block Executed by:
| 34925 | ||||||||||||||||||
112 | } executed 34936 times by 9 tests: end of block Executed by:
| 34936 | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | void ResultStoreBase::insertResultItemIfValid(int index, ResultItem &resultItem) | - | ||||||||||||||||||
115 | { | - | ||||||||||||||||||
116 | if (resultItem.isValid()) {
| 229-34936 | ||||||||||||||||||
117 | m_results[index] = resultItem; | - | ||||||||||||||||||
118 | syncResultCount(); | - | ||||||||||||||||||
119 | } else { executed 34936 times by 9 tests: end of block Executed by:
| 34936 | ||||||||||||||||||
120 | filteredResults += resultItem.count(); | - | ||||||||||||||||||
121 | } executed 229 times by 4 tests: end of block Executed by:
| 229 | ||||||||||||||||||
122 | } | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | int ResultStoreBase::insertResultItem(int index, ResultItem &resultItem) | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | int storeIndex; | - | ||||||||||||||||||
127 | if (m_filterMode && index != -1 && index > insertIndex) {
| 0-34676 | ||||||||||||||||||
128 | pendingResults[index] = resultItem; | - | ||||||||||||||||||
129 | storeIndex = index; | - | ||||||||||||||||||
130 | } else { executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
131 | storeIndex = updateInsertIndex(index, resultItem.count()); | - | ||||||||||||||||||
132 | insertResultItemIfValid(storeIndex - filteredResults, resultItem); | - | ||||||||||||||||||
133 | } executed 35107 times by 9 tests: end of block Executed by:
| 35107 | ||||||||||||||||||
134 | syncPendingResults(); | - | ||||||||||||||||||
135 | return storeIndex; executed 35165 times by 9 tests: return storeIndex; Executed by:
| 35165 | ||||||||||||||||||
136 | } | - | ||||||||||||||||||
137 | - | |||||||||||||||||||
138 | void ResultStoreBase::syncPendingResults() | - | ||||||||||||||||||
139 | { | - | ||||||||||||||||||
140 | // check if we can insert any of the pending results: | - | ||||||||||||||||||
141 | QMap<int, ResultItem>::iterator it = pendingResults.begin(); | - | ||||||||||||||||||
142 | while (it != pendingResults.end()) {
| 102-35121 | ||||||||||||||||||
143 | int index = it.key(); | - | ||||||||||||||||||
144 | if (index != resultCount + filteredResults)
| 44-58 | ||||||||||||||||||
145 | break; executed 44 times by 2 tests: break; Executed by:
| 44 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | ResultItem result = it.value(); | - | ||||||||||||||||||
148 | insertResultItemIfValid(index - filteredResults, result); | - | ||||||||||||||||||
149 | pendingResults.erase(it); | - | ||||||||||||||||||
150 | it = pendingResults.begin(); | - | ||||||||||||||||||
151 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
152 | } executed 35165 times by 9 tests: end of block Executed by:
| 35165 | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | int ResultStoreBase::addResult(int index, const void *result) | - | ||||||||||||||||||
155 | { | - | ||||||||||||||||||
156 | ResultItem resultItem(result, 0); // 0 means "not a vector" | - | ||||||||||||||||||
157 | return insertResultItem(index, resultItem); executed 34625 times by 9 tests: return insertResultItem(index, resultItem); Executed by:
| 34625 | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount) | - | ||||||||||||||||||
161 | { | - | ||||||||||||||||||
162 | if (m_filterMode == false || vectorSize == totalCount) {
| 49-231 | ||||||||||||||||||
163 | ResultItem resultItem(results, vectorSize); | - | ||||||||||||||||||
164 | return insertResultItem(index, resultItem); executed 222 times by 5 tests: return insertResultItem(index, resultItem); Executed by:
| 222 | ||||||||||||||||||
165 | } else { | - | ||||||||||||||||||
166 | if (vectorSize > 0) {
| 46-136 | ||||||||||||||||||
167 | ResultItem filteredIn(results, vectorSize); | - | ||||||||||||||||||
168 | insertResultItem(index, filteredIn); | - | ||||||||||||||||||
169 | } executed 136 times by 2 tests: end of block Executed by:
| 136 | ||||||||||||||||||
170 | ResultItem filteredAway(0, totalCount - vectorSize); | - | ||||||||||||||||||
171 | return insertResultItem(index + vectorSize, filteredAway); executed 182 times by 4 tests: return insertResultItem(index + vectorSize, filteredAway); Executed by:
| 182 | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | } | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | ResultIteratorBase ResultStoreBase::begin() const | - | ||||||||||||||||||
176 | { | - | ||||||||||||||||||
177 | return ResultIteratorBase(m_results.begin()); executed 147 times by 7 tests: return ResultIteratorBase(m_results.begin()); Executed by:
| 147 | ||||||||||||||||||
178 | } | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | ResultIteratorBase ResultStoreBase::end() const | - | ||||||||||||||||||
181 | { | - | ||||||||||||||||||
182 | return ResultIteratorBase(m_results.end()); executed 114471 times by 9 tests: return ResultIteratorBase(m_results.end()); Executed by:
| 114471 | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | bool ResultStoreBase::hasNextResult() const | - | ||||||||||||||||||
186 | { | - | ||||||||||||||||||
187 | return begin() != end(); never executed: return begin() != end(); | 0 | ||||||||||||||||||
188 | } | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | ResultIteratorBase ResultStoreBase::resultAt(int index) const | - | ||||||||||||||||||
191 | { | - | ||||||||||||||||||
192 | if (m_results.isEmpty())
| 252-189848 | ||||||||||||||||||
193 | return ResultIteratorBase(m_results.end()); executed 252 times by 8 tests: return ResultIteratorBase(m_results.end()); Executed by:
| 252 | ||||||||||||||||||
194 | QMap<int, ResultItem>::const_iterator it = m_results.lowerBound(index); | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | // lowerBound returns either an iterator to the result or an iterator | - | ||||||||||||||||||
197 | // to the nearest greater index. If the latter happens it might be | - | ||||||||||||||||||
198 | // that the result is stored in a vector at the previous index. | - | ||||||||||||||||||
199 | if (it == m_results.end()) {
| 42360-147488 | ||||||||||||||||||
200 | --it; | - | ||||||||||||||||||
201 | if (it.value().isVector() == false) {
| 7559-34801 | ||||||||||||||||||
202 | return ResultIteratorBase(m_results.end()); executed 34801 times by 9 tests: return ResultIteratorBase(m_results.end()); Executed by:
| 34801 | ||||||||||||||||||
203 | } | - | ||||||||||||||||||
204 | } else { executed 7559 times by 5 tests: end of block Executed by:
| 7559 | ||||||||||||||||||
205 | if (it.key() > index) {
| 51861-95627 | ||||||||||||||||||
206 | if (it == m_results.begin())
| 24-51837 | ||||||||||||||||||
207 | return ResultIteratorBase(m_results.end()); executed 24 times by 2 tests: return ResultIteratorBase(m_results.end()); Executed by:
| 24 | ||||||||||||||||||
208 | --it; | - | ||||||||||||||||||
209 | } executed 51837 times by 5 tests: end of block Executed by:
| 51837 | ||||||||||||||||||
210 | } executed 147464 times by 9 tests: end of block Executed by:
| 147464 | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | const int vectorIndex = index - it.key(); | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | if (vectorIndex >= it.value().count())
| 401-154622 | ||||||||||||||||||
215 | return ResultIteratorBase(m_results.end()); executed 401 times by 5 tests: return ResultIteratorBase(m_results.end()); Executed by:
| 401 | ||||||||||||||||||
216 | else if (it.value().isVector() == false && vectorIndex != 0)
| 0-84772 | ||||||||||||||||||
217 | return ResultIteratorBase(m_results.end()); never executed: return ResultIteratorBase(m_results.end()); | 0 | ||||||||||||||||||
218 | return ResultIteratorBase(it, vectorIndex); executed 154622 times by 9 tests: return ResultIteratorBase(it, vectorIndex); Executed by:
| 154622 | ||||||||||||||||||
219 | } | - | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | bool ResultStoreBase::contains(int index) const | - | ||||||||||||||||||
222 | { | - | ||||||||||||||||||
223 | return (resultAt(index) != end()); executed 43712 times by 9 tests: return (resultAt(index) != end()); Executed by:
| 43712 | ||||||||||||||||||
224 | } | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | int ResultStoreBase::count() const | - | ||||||||||||||||||
227 | { | - | ||||||||||||||||||
228 | return resultCount; executed 29508 times by 5 tests: return resultCount; Executed by:
| 29508 | ||||||||||||||||||
229 | } | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | // returns the insert index, calling this function with | - | ||||||||||||||||||
232 | // index equal to -1 returns the next available index. | - | ||||||||||||||||||
233 | int ResultStoreBase::updateInsertIndex(int index, int _count) | - | ||||||||||||||||||
234 | { | - | ||||||||||||||||||
235 | if (index == -1) {
| 1068-34039 | ||||||||||||||||||
236 | index = insertIndex; | - | ||||||||||||||||||
237 | insertIndex += _count; | - | ||||||||||||||||||
238 | } else { executed 34039 times by 8 tests: end of block Executed by:
| 34039 | ||||||||||||||||||
239 | insertIndex = qMax(index + _count, insertIndex); | - | ||||||||||||||||||
240 | } executed 1068 times by 6 tests: end of block Executed by:
| 1068 | ||||||||||||||||||
241 | return index; executed 35107 times by 9 tests: return index; Executed by:
| 35107 | ||||||||||||||||||
242 | } | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | } // namespace QtPrivate | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | QT_END_NAMESPACE | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | #endif // QT_NO_QFUTURE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |