thread/qresultstore.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 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:1318475
1318475
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:261469
261469
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:536586
536586
83} -
84 -
85bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const -
86{ -
87 return !operator==(other);
executed: return !operator==(other);
Execution Count:536020
536020
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:583050
583050
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:263712
263712
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:261839
yes
Evaluation Count:260700
260700-261839
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:261126
261126
120}
executed: }
Execution Count:260403
260403
121 -
122void ResultStoreBase::insertResultItemIfValid(int index, ResultItem &resultItem) -
123{ -
124 if (resultItem.isValid()) {
evaluated: resultItem.isValid()
TRUEFALSE
yes
Evaluation Count:262382
yes
Evaluation Count:677
677-262382
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:260531
260531
128 filteredResults += resultItem.count();
executed (the execution status of this line is deduced): filteredResults += resultItem.count();
-
129 }
executed: }
Execution Count:677
677
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:1388
yes
Evaluation Count:263101
partially evaluated: index != -1
TRUEFALSE
yes
Evaluation Count:1388
no
Evaluation Count:0
evaluated: index > insertIndex
TRUEFALSE
yes
Evaluation Count:1265
yes
Evaluation Count:123
0-263101
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:1265
1265
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:260084
260084
142 syncPendingResults();
executed (the execution status of this line is deduced): syncPendingResults();
-
143 return storeIndex;
executed: return storeIndex;
Execution Count:264885
264885
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:2426
yes
Evaluation Count:263891
2426-263891
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:1161
yes
Evaluation Count:1265
1161-1265
153 break;
executed: break;
Execution Count:1161
1161
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:1265
1265
160}
executed: }
Execution Count:264885
264885
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:263660
263660
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:199
yes
Evaluation Count:754
evaluated: vectorSize == totalCount
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:630
124-754
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:323
323
173 } else { -
174 if (vectorSize > 0) {
evaluated: vectorSize > 0
TRUEFALSE
yes
Evaluation Count:512
yes
Evaluation Count:118
118-512
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:512
512
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:630
630
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:536683
536683
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:399
yes
Evaluation Count:805378
399-805378
201 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:399
399
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:260364
yes
Evaluation Count:555887
260364-555887
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:259128
yes
Evaluation Count:1070
1070-259128
210 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:259193
259193
211 } -
212 } else {
executed: }
Execution Count:1070
1070
213 if (it.key() > index) {
evaluated: it.key() > index
TRUEFALSE
yes
Evaluation Count:30113
yes
Evaluation Count:526183
30113-526183
214 if (it == m_results.begin())
evaluated: it == m_results.begin()
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:30074
39-30074
215 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:39
39
216 --it;
executed (the execution status of this line is deduced): --it;
-
217 }
executed: }
Execution Count:30074
30074
218 }
executed: }
Execution Count:555953
555953
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:2174
yes
Evaluation Count:554265
2174-554265
223 return ResultIteratorBase(m_results.end());
executed: return ResultIteratorBase(m_results.end());
Execution Count:2174
2174
224 else if (it.value().isVector() == false && vectorIndex != 0)
evaluated: it.value().isVector() == false
TRUEFALSE
yes
Evaluation Count:521479
yes
Evaluation Count:33076
partially evaluated: vectorIndex != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:521985
0-521985
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:554036
554036
227} -
228 -
229bool ResultStoreBase::contains(int index) const -
230{ -
231 return (resultAt(index) != end());
executed: return (resultAt(index) != end());
Execution Count:19045
19045
232} -
233 -
234int ResultStoreBase::count() const -
235{ -
236 return resultCount;
executed: return resultCount;
Execution Count:5560
5560
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:260864
yes
Evaluation Count:1969
1969-260864
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:260703
260703
247 insertIndex = qMax(index + _count, insertIndex);
executed (the execution status of this line is deduced): insertIndex = qMax(index + _count, insertIndex);
-
248 }
executed: }
Execution Count:1969
1969
249 return index;
executed: return index;
Execution Count:262701
262701
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