json/qjsonarray.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4QJsonArray::QJsonArray() -
5 : d(0), a(0) -
6{ -
7}
executed: }
Execution Count:11614
11614
8 -
9 -
10 -
11 -
12QJsonArray::QJsonArray(QJsonPrivate::Data *data, QJsonPrivate::Array *array) -
13 : d(data), a(array) -
14{ -
15 qt_noop(); -
16 qt_noop(); -
17 d->ref.ref(); -
18}
executed: }
Execution Count:12006
12006
19 -
20 -
21 -
22 -
23QJsonArray::~QJsonArray() -
24{ -
25 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:12484
yes
Evaluation Count:11594
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:12456
28-12484
26 delete d;
executed: delete d;
Execution Count:28
28
27}
executed: }
Execution Count:24078
24078
28 -
29 -
30 -
31 -
32 -
33 -
34 -
35QJsonArray::QJsonArray(const QJsonArray &other) -
36{ -
37 d = other.d; -
38 a = other.a; -
39 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:449
yes
Evaluation Count:9
9-449
40 d->ref.ref();
executed: d->ref.ref();
Execution Count:449
449
41}
executed: }
Execution Count:458
458
42 -
43 -
44 -
45 -
46QJsonArray &QJsonArray::operator =(const QJsonArray &other) -
47{ -
48 if (d != other.d) {
partially evaluated: d != other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
49 if (d && !d->ref.deref())
never evaluated: d
never evaluated: !d->ref.deref()
0
50 delete d;
never executed: delete d;
0
51 d = other.d; -
52 if (d)
never evaluated: d
0
53 d->ref.ref();
never executed: d->ref.ref();
0
54 }
never executed: }
0
55 a = other.a; -
56 -
57 return *this;
executed: return *this;
Execution Count:3
3
58} -
59QJsonArray QJsonArray::fromStringList(const QStringList &list) -
60{ -
61 QJsonArray array; -
62 for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
never evaluated: it != list.constEnd()
0
63 array.append(QJsonValue(*it));
never executed: array.append(QJsonValue(*it));
0
64 return array;
never executed: return array;
0
65} -
66QJsonArray QJsonArray::fromVariantList(const QVariantList &list) -
67{ -
68 QJsonArray array; -
69 for (QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
evaluated: it != list.constEnd()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1
1-4
70 array.append(QJsonValue::fromVariant(*it));
executed: array.append(QJsonValue::fromVariant(*it));
Execution Count:4
4
71 return array;
executed: return array;
Execution Count:1
1
72} -
73 -
74 -
75 -
76 -
77 -
78 -
79QVariantList QJsonArray::toVariantList() const -
80{ -
81 QVariantList list; -
82 -
83 if (a) {
evaluated: a
TRUEFALSE
yes
Evaluation Count:103
yes
Evaluation Count:1
1-103
84 for (int i = 0; i < (int)a->length; ++i)
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:491
yes
Evaluation Count:103
103-491
85 list.append(QJsonValue(d, a, a->at(i)).toVariant());
executed: list.append(QJsonValue(d, a, a->at(i)).toVariant());
Execution Count:491
491
86 }
executed: }
Execution Count:103
103
87 return list;
executed: return list;
Execution Count:104
104
88} -
89 -
90 -
91 -
92 -
93 -
94int QJsonArray::size() const -
95{ -
96 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:12017
3-12017
97 return 0;
executed: return 0;
Execution Count:3
3
98 -
99 return (int)a->length;
executed: return (int)a->length;
Execution Count:12017
12017
100} -
101bool QJsonArray::isEmpty() const -
102{ -
103 if (!d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
104 return true;
never executed: return true;
0
105 -
106 return !a->length;
executed: return !a->length;
Execution Count:12
12
107} -
108 -
109 -
110 -
111 -
112 -
113 -
114 -
115QJsonValue QJsonArray::at(int i) const -
116{ -
117 if (!a || i < 0 || i >= (int)a->length)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:22729
evaluated: i < 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22726
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22723
2-22729
118 return QJsonValue(QJsonValue::Undefined);
executed: return QJsonValue(QJsonValue::Undefined);
Execution Count:8
8
119 -
120 return QJsonValue(d, a, a->at(i));
executed: return QJsonValue(d, a, a->at(i));
Execution Count:22723
22723
121} -
122QJsonValue QJsonArray::first() const -
123{ -
124 return at(0);
executed: return at(0);
Execution Count:9
9
125} -
126QJsonValue QJsonArray::last() const -
127{ -
128 return at(a ? (a->length - 1) : 0);
executed: return at(a ? (a->length - 1) : 0);
Execution Count:10
10
129} -
130void QJsonArray::prepend(const QJsonValue &value) -
131{ -
132 insert(0, value); -
133}
executed: }
Execution Count:1
1
134 -
135 -
136 -
137 -
138 -
139 -
140void QJsonArray::append(const QJsonValue &value) -
141{ -
142 insert(a ? (int)a->length : 0, value); -
143}
executed: }
Execution Count:121
121
144 -
145 -
146 -
147 -
148 -
149 -
150 -
151void QJsonArray::removeAt(int i) -
152{ -
153 if (!a || i < 0 || i >= (int)a->length)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:19
evaluated: i < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:17
1-19
154 return;
executed: return;
Execution Count:4
4
155 -
156 detach(); -
157 a->removeItems(i, 1); -
158 ++d->compactionCounter; -
159 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
partially evaluated: d->compactionCounter > 32u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
never evaluated: d->compactionCounter >= unsigned(a->length) / 2u
0-17
160 compact();
never executed: compact();
0
161}
executed: }
Execution Count:17
17
162QJsonValue QJsonArray::takeAt(int i) -
163{ -
164 if (!a || i < 0 || i >= (int)a->length)
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
evaluated: !a
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
partially evaluated: i < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
165 return QJsonValue(QJsonValue::Undefined);
executed: return QJsonValue(QJsonValue::Undefined);
Execution Count:2
2
166 -
167 QJsonValue v(d, a, a->at(i)); -
168 removeAt(i); -
169 return v;
executed: return v;
Execution Count:1
1
170} -
171void QJsonArray::insert(int i, const QJsonValue &value) -
172{ -
173 qt_noop(); -
174 -
175 bool compressed; -
176 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed); -
177 -
178 detach(valueSize + sizeof(QJsonPrivate::Value)); -
179 -
180 if (!a->length)
evaluated: !a->length
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:93
29-93
181 a->tableOffset = sizeof(QJsonPrivate::Array);
executed: a->tableOffset = sizeof(QJsonPrivate::Array);
Execution Count:29
29
182 -
183 int valueOffset = a->reserveSpace(valueSize, i, 1, false); -
184 QJsonPrivate::Value &v = (*a)[i]; -
185 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
evaluated: value.t == QJsonValue::Undefined
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:121
1-121
186 v.latinOrIntValue = compressed; -
187 v.latinKey = false; -
188 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset); -
189 if (valueSize)
evaluated: valueSize
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:65
57-65
190 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
executed: QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
Execution Count:57
57
191}
executed: }
Execution Count:122
122
192void QJsonArray::replace(int i, const QJsonValue &value) -
193{ -
194 qt_noop(); -
195 -
196 bool compressed; -
197 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed); -
198 -
199 detach(valueSize); -
200 -
201 if (!a->length)
partially evaluated: !a->length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
202 a->tableOffset = sizeof(QJsonPrivate::Array);
never executed: a->tableOffset = sizeof(QJsonPrivate::Array);
0
203 -
204 int valueOffset = a->reserveSpace(valueSize, i, 1, true); -
205 QJsonPrivate::Value &v = (*a)[i]; -
206 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
partially evaluated: value.t == QJsonValue::Undefined
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
207 v.latinOrIntValue = compressed; -
208 v.latinKey = false; -
209 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset); -
210 if (valueSize)
partially evaluated: valueSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
211 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
never executed: QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
0
212 -
213 ++d->compactionCounter; -
214 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
partially evaluated: d->compactionCounter > 32u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
never evaluated: d->compactionCounter >= unsigned(a->length) / 2u
0-4
215 compact();
never executed: compact();
0
216}
executed: }
Execution Count:4
4
217 -
218 -
219 -
220 -
221 -
222 -
223bool QJsonArray::contains(const QJsonValue &value) const -
224{ -
225 for (int i = 0; i < size(); i++) {
never evaluated: i < size()
0
226 if (at(i) == value)
never evaluated: at(i) == value
0
227 return true;
never executed: return true;
0
228 }
never executed: }
0
229 return false;
never executed: return false;
0
230} -
231QJsonValueRef QJsonArray::operator [](int i) -
232{ -
233 qt_noop(); -
234 return QJsonValueRef(this, i);
executed: return QJsonValueRef(this, i);
Execution Count:6
6
235} -
236 -
237 -
238 -
239 -
240 -
241 -
242QJsonValue QJsonArray::operator[](int i) const -
243{ -
244 return at(i);
never executed: return at(i);
0
245} -
246 -
247 -
248 -
249 -
250bool QJsonArray::operator==(const QJsonArray &other) const -
251{ -
252 if (a == other.a)
evaluated: a == other.a
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:160
19-160
253 return true;
executed: return true;
Execution Count:19
19
254 -
255 if (!a)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:159
1-159
256 return !other.a->length;
executed: return !other.a->length;
Execution Count:1
1
257 if (!other.a)
evaluated: !other.a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:157
2-157
258 return !a->length;
executed: return !a->length;
Execution Count:2
2
259 if (a->length != other.a->length)
evaluated: a->length != other.a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:156
1-156
260 return false;
executed: return false;
Execution Count:1
1
261 -
262 for (int i = 0; i < (int)a->length; ++i) {
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:727
yes
Evaluation Count:155
155-727
263 if (QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i)))
evaluated: QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:726
1-726
264 return false;
executed: return false;
Execution Count:1
1
265 }
executed: }
Execution Count:726
726
266 return true;
executed: return true;
Execution Count:155
155
267} -
268 -
269 -
270 -
271 -
272bool QJsonArray::operator!=(const QJsonArray &other) const -
273{ -
274 return !(*this == other);
executed: return !(*this == other);
Execution Count:3
3
275} -
276void QJsonArray::detach(uint reserve) -
277{ -
278 if (!d) {
evaluated: !d
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:137
29-137
279 d = new QJsonPrivate::Data(reserve, QJsonValue::Array); -
280 a = static_cast<QJsonPrivate::Array *>(d->header->root()); -
281 d->ref.ref(); -
282 return;
executed: return;
Execution Count:29
29
283 } -
284 if (reserve == 0 && d->ref.load() == 1)
evaluated: reserve == 0
TRUEFALSE
yes
Evaluation Count:44
yes
Evaluation Count:93
evaluated: d->ref.load() == 1
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:8
8-93
285 return;
executed: return;
Execution Count:36
36
286 -
287 QJsonPrivate::Data *x = d->clone(a, reserve); -
288 x->ref.ref(); -
289 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:80
21-80
290 delete d;
executed: delete d;
Execution Count:21
21
291 d = x; -
292 a = static_cast<QJsonPrivate::Array *>(d->header->root()); -
293}
executed: }
Execution Count:101
101
294 -
295 -
296 -
297 -
298void QJsonArray::compact() -
299{ -
300 if (!d || !d->compactionCounter)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !d->compactionCounter
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
301 return;
never executed: return;
0
302 -
303 detach(); -
304 d->compact(); -
305 a = static_cast<QJsonPrivate::Array *>(d->header->root()); -
306}
executed: }
Execution Count:3
3
307 -
308 -
309 -
310QDebug operator<<(QDebug dbg, const QJsonArray &a) -
311{ -
312 if (!a.a) {
evaluated: !a.a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
313 dbg << "QJsonArray()"; -
314 return dbg;
executed: return dbg;
Execution Count:2
2
315 } -
316 QByteArray json; -
317 QJsonPrivate::Writer::arrayToJson(a.a, json, 0, true); -
318 dbg.nospace() << "QJsonArray(" -
319 << json.constData() -
320 << ")"; -
321 return dbg.space();
executed: return dbg.space();
Execution Count:2
2
322} -
323 -
324 -
325 -
326 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial