thread/qresultstore.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qresultstore.h" -
43 -
44#ifndef QT_NO_QFUTURE -
45 -
46QT_BEGIN_NAMESPACE -
47 -
48namespace QtPrivate { -
49 -
50ResultIteratorBase::ResultIteratorBase() -
51 : mapIterator(QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { }
never executed: }
0
52ResultIteratorBase::ResultIteratorBase(QMap<int, ResultItem>::const_iterator _mapIterator, int _vectorIndex) -
53 : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { }
executed: }
Execution Count:1319933
1319933
54 -
55int ResultIteratorBase::vectorIndex() const { return m_vectorIndex; }
never executed: return m_vectorIndex;
0
56int ResultIteratorBase::resultIndex() const { return mapIterator.key() + m_vectorIndex; }
executed: return mapIterator.key() + m_vectorIndex;
Execution Count:37
37
57 -
58ResultIteratorBase ResultIteratorBase::operator++() -
59{ -
60 if (canIncrementVectorIndex()) {
evaluated: canIncrementVectorIndex()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:574
15-574
61 ++m_vectorIndex;
executed (the execution status of this line is deduced): ++m_vectorIndex;
-
62 } else {
executed: }
Execution Count:15
15
63 ++mapIterator;
executed (the execution status of this line is deduced): ++mapIterator;
-
64 m_vectorIndex = 0;
executed (the execution status of this line is deduced): m_vectorIndex = 0;
-
65 }
executed: }
Execution Count:574
574
66 return *this;
executed: return *this;
Execution Count:589
589
67} -
68 -
69int ResultIteratorBase::batchSize() const -
70{ -
71 return mapIterator.value().count();
executed: return mapIterator.value().count();
Execution Count:261934
261934
72} -
73 -
74void ResultIteratorBase::batchedAdvance() -
75{ -
76 ++mapIterator;
executed (the execution status of this line is deduced): ++mapIterator;
-
77 m_vectorIndex = 0;
executed (the execution status of this line is deduced): m_vectorIndex = 0;
-
78}
executed: }
Execution Count:9
9
79 -
80bool ResultIteratorBase::operator==(const ResultIteratorBase &other) const -
81{ -
82 return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);
executed: return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);
Execution Count:537457
537457
83} -
84 -
85bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const -
86{ -
87 return !operator==(other);
executed: return !operator==(other);
Execution Count:536912
536912
88} -
89 -
90bool ResultIteratorBase::isVector() const -
91{ -
92 return mapIterator.value().isVector();
never executed: return mapIterator.value().isVector();
0
93} -
94 -
95bool ResultIteratorBase::canIncrementVectorIndex() const -
96{ -
97 return (m_vectorIndex + 1 < mapIterator.value().m_count);
executed: return (m_vectorIndex + 1 < mapIterator.value().m_count);
Execution Count:589
589
98} -
99 -
100ResultStoreBase::ResultStoreBase() -
101 : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { }
executed: }
Execution Count:583124
583124
102 -
103void ResultStoreBase::setFilterMode(bool enable) -
104{ -
105 m_filterMode = enable;
executed (the execution status of this line is deduced): m_filterMode = enable;
-
106}
executed: }
Execution Count:50
50
107 -
108bool ResultStoreBase::filterMode() const -
109{ -
110 return m_filterMode;
executed: return m_filterMode;
Execution Count:264180
264180
111} -
112 -
113void ResultStoreBase::syncResultCount() -
114{ -
115 ResultIteratorBase it = resultAt(resultCount);
executed (the execution status of this line is deduced): ResultIteratorBase it = resultAt(resultCount);
-
116 while (it != end()) {
evaluated: it != end()
TRUEFALSE
yes
Evaluation Count:262218
yes
Evaluation Count:261217
261217-262218
117 resultCount += it.batchSize();
executed (the execution status of this line is deduced): resultCount += it.batchSize();
-
118 it = resultAt(resultCount);
executed (the execution status of this line is deduced): it = resultAt(resultCount);
-
119 }
executed: }
Execution Count:261603
261603
120}
executed: }
Execution Count:260932
260932
121 -
122void ResultStoreBase::insertResultItemIfValid(int index, ResultItem &resultItem) -
123{ -
124 if (resultItem.isValid()) {
evaluated: resultItem.isValid()
TRUEFALSE
yes
Evaluation Count:263275
yes
Evaluation Count:759
759-263275
125 m_results[index] = resultItem;
executed (the execution status of this line is deduced): m_results[index] = resultItem;
-
126 syncResultCount();
executed (the execution status of this line is deduced): syncResultCount();
-
127 } else {
executed: }
Execution Count:261071
261071
128 filteredResults += resultItem.count();
executed (the execution status of this line is deduced): filteredResults += resultItem.count();
-
129 }
executed: }
Execution Count:759
759
130} -
131 -
132int ResultStoreBase::insertResultItem(int index, ResultItem &resultItem) -
133{ -
134 int storeIndex;
executed (the execution status of this line is deduced): int storeIndex;
-
135 if (m_filterMode && index != -1 && index > insertIndex) {
evaluated: m_filterMode
TRUEFALSE
yes
Evaluation Count:1552
yes
Evaluation Count:263744
partially evaluated: index != -1
TRUEFALSE
yes
Evaluation Count:1552
no
Evaluation Count:0
evaluated: index > insertIndex
TRUEFALSE
yes
Evaluation Count:1430
yes
Evaluation Count:122
0-263744
136 pendingResults[index] = resultItem;
executed (the execution status of this line is deduced): pendingResults[index] = resultItem;
-
137 storeIndex = index;
executed (the execution status of this line is deduced): storeIndex = index;
-
138 } else {
executed: }
Execution Count:1430
1430
139 storeIndex = updateInsertIndex(index, resultItem.count());
executed (the execution status of this line is deduced): storeIndex = updateInsertIndex(index, resultItem.count());
-
140 insertResultItemIfValid(storeIndex - filteredResults, resultItem);
executed (the execution status of this line is deduced): insertResultItemIfValid(storeIndex - filteredResults, resultItem);
-
141 }
executed: }
Execution Count:260546
260546
142 syncPendingResults();
executed (the execution status of this line is deduced): syncPendingResults();
-
143 return storeIndex;
executed: return storeIndex;
Execution Count:265406
265406
144} -
145 -
146void ResultStoreBase::syncPendingResults() -
147{ -
148 // check if we can insert any of the pending results: -
149 QMap<int, ResultItem>::iterator it = pendingResults.begin();
executed (the execution status of this line is deduced): QMap<int, ResultItem>::iterator it = pendingResults.begin();
-
150 while (it != pendingResults.end()) {
evaluated: it != pendingResults.end()
TRUEFALSE
yes
Evaluation Count:2716
yes
Evaluation Count:264352
2716-264352
151 int index = it.key();
executed (the execution status of this line is deduced): int index = it.key();
-
152 if (index != resultCount + filteredResults)
evaluated: index != resultCount + filteredResults
TRUEFALSE
yes
Evaluation Count:1286
yes
Evaluation Count:1430
1286-1430
153 break;
executed: break;
Execution Count:1286
1286
154 -
155 ResultItem result = it.value();
executed (the execution status of this line is deduced): ResultItem result = it.value();
-
156 insertResultItemIfValid(index - filteredResults, result);
executed (the execution status of this line is deduced): insertResultItemIfValid(index - filteredResults, result);
-
157 pendingResults.erase(it);
executed (the execution status of this line is deduced): pendingResults.erase(it);
-
158 it = pendingResults.begin();
executed (the execution status of this line is deduced): it = pendingResults.begin();
-
159 }
executed: }
Execution Count:1430
1430
160}
executed: }
Execution Count:265481
265481
161 -
162int ResultStoreBase::addResult(int index, const void *result) -
163{ -
164 ResultItem resultItem(result, 0); // 0 means "not a vector"
executed (the execution status of this line is deduced): ResultItem resultItem(result, 0);
-
165 return insertResultItem(index, resultItem);
executed: return insertResultItem(index, resultItem);
Execution Count:263957
263957
166} -
167 -
168int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount) -
169{ -
170 if (m_filterMode == false || vectorSize == totalCount) {
evaluated: m_filterMode == false
TRUEFALSE
yes
Evaluation Count:443
yes
Evaluation Count:836
evaluated: vectorSize == totalCount
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:712
124-836
171 ResultItem resultItem(results, vectorSize);
executed (the execution status of this line is deduced): ResultItem resultItem(results, vectorSize);
-
172 return insertResultItem(index, resultItem);
executed: return insertResultItem(index, resultItem);
Execution Count:567
567
173 } else { -
174 if (vectorSize > 0) {
evaluated: vectorSize > 0
TRUEFALSE
yes
Evaluation Count:594
yes
Evaluation Count:118
118-594
175 ResultItem filteredIn(results, vectorSize);
executed (the execution status of this line is deduced): ResultItem filteredIn(results, vectorSize);
-
176 insertResultItem(index, filteredIn);
executed (the execution status of this line is deduced): insertResultItem(index, filteredIn);
-
177 }
executed: }
Execution Count:594
594
178 ResultItem filteredAway(0, totalCount - vectorSize);
executed (the execution status of this line is deduced): ResultItem filteredAway(0, totalCount - vectorSize);
-
179 return insertResultItem(index + vectorSize, filteredAway);
executed: return insertResultItem(index + vectorSize, filteredAway);
Execution Count:712
712
180 } -
181} -
182 -
183ResultIteratorBase ResultStoreBase::begin() const -
184{ -
185 return ResultIteratorBase(m_results.begin());
executed: return ResultIteratorBase(m_results.begin());
Execution Count:147
147
186} -
187 -
188ResultIteratorBase ResultStoreBase::end() const -
189{ -
190 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:537872
537872
191} -
192 -
193bool ResultStoreBase::hasNextResult() const -
194{ -
195 return begin() != end();
never executed: return begin() != end();
0
196} -
197 -
198ResultIteratorBase ResultStoreBase::resultAt(int index) const -
199{ -
200 if (m_results.isEmpty())
evaluated: m_results.isEmpty()
TRUEFALSE
yes
Evaluation Count:397
yes
Evaluation Count:805599
397-805599
201 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:397
397
202 QMap<int, ResultItem>::const_iterator it = m_results.lowerBound(index);
executed (the execution status of this line is deduced): QMap<int, ResultItem>::const_iterator it = m_results.lowerBound(index);
-
203 -
204 // lowerBound returns either an iterator to the result or an iterator -
205 // to the nearest greater index. If the latter happens it might be -
206 // that the result is stored in a vector at the previous index. -
207 if (it == m_results.end()) {
evaluated: it == m_results.end()
TRUEFALSE
yes
Evaluation Count:259905
yes
Evaluation Count:557084
259905-557084
208 --it;
executed (the execution status of this line is deduced): --it;
-
209 if (it.value().isVector() == false) {
evaluated: it.value().isVector() == false
TRUEFALSE
yes
Evaluation Count:258877
yes
Evaluation Count:803
803-258877
210 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:258965
258965
211 } -
212 } else {
executed: }
Execution Count:803
803
213 if (it.key() > index) {
evaluated: it.key() > index
TRUEFALSE
yes
Evaluation Count:30410
yes
Evaluation Count:527121
30410-527121
214 if (it == m_results.begin())
evaluated: it == m_results.begin()
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:30368
42-30368
215 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:42
42
216 --it;
executed (the execution status of this line is deduced): --it;
-
217 }
executed: }
Execution Count:30368
30368
218 }
executed: }
Execution Count:557153
557153
219 -
220 const int vectorIndex = index - it.key();
executed (the execution status of this line is deduced): const int vectorIndex = index - it.key();
-
221 -
222 if (vectorIndex >= it.value().count())
evaluated: vectorIndex >= it.value().count()
TRUEFALSE
yes
Evaluation Count:2884
yes
Evaluation Count:554648
2884-554648
223 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:2884
2884
224 else if (it.value().isVector() == false && vectorIndex != 0)
evaluated: it.value().isVector() == false
TRUEFALSE
yes
Evaluation Count:521694
yes
Evaluation Count:33299
partially evaluated: vectorIndex != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:522277
0-522277
225 return ResultIteratorBase(m_results.end());
never executed: return ResultIteratorBase(m_results.end());
0
226 return ResultIteratorBase(it, vectorIndex);
executed: return ResultIteratorBase(it, vectorIndex);
Execution Count:554557
554557
227} -
228 -
229bool ResultStoreBase::contains(int index) const -
230{ -
231 return (resultAt(index) != end());
executed: return (resultAt(index) != end());
Execution Count:19161
19161
232} -
233 -
234int ResultStoreBase::count() const -
235{ -
236 return resultCount;
executed: return resultCount;
Execution Count:5823
5823
237} -
238 -
239// returns the insert index, calling this function with -
240// index equal to -1 returns the next available index. -
241int ResultStoreBase::updateInsertIndex(int index, int _count) -
242{ -
243 if (index == -1) {
evaluated: index == -1
TRUEFALSE
yes
Evaluation Count:260913
yes
Evaluation Count:2552
2552-260913
244 index = insertIndex;
executed (the execution status of this line is deduced): index = insertIndex;
-
245 insertIndex += _count;
executed (the execution status of this line is deduced): insertIndex += _count;
-
246 } else {
executed: }
Execution Count:260751
260751
247 insertIndex = qMax(index + _count, insertIndex);
executed (the execution status of this line is deduced): insertIndex = qMax(index + _count, insertIndex);
-
248 }
executed: }
Execution Count:2552
2552
249 return index;
executed: return index;
Execution Count:263362
263362
250} -
251 -
252} // namespace QtPrivate -
253 -
254QT_END_NAMESPACE -
255 -
256#endif // QT_NO_QFUTURE -
257 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial