json/qjson.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 "qjson_p.h" -
43#include <qalgorithms.h> -
44 -
45QT_BEGIN_NAMESPACE -
46 -
47namespace QJsonPrivate -
48{ -
49 -
50#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN -
51#define Q_TO_LITTLE_ENDIAN(x) (x) -
52#else -
53#define Q_TO_LITTLE_ENDIAN(x) ( ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x & 0xff000000) >> 24) ) -
54#endif -
55 -
56static const Base emptyArray = { { Q_TO_LITTLE_ENDIAN(sizeof(Base)) }, { 0 }, { 0 } }; -
57static const Base emptyObject = { { Q_TO_LITTLE_ENDIAN(sizeof(Base)) }, { 0 }, { 0 } }; -
58 -
59 -
60void Data::compact() -
61{ -
62 Q_ASSERT(sizeof(Value) == sizeof(offset));
executed (the execution status of this line is deduced): qt_noop();
-
63 -
64 if (!compactionCounter)
partially evaluated: !compactionCounter
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
65 return;
never executed: return;
0
66 -
67 Base *base = header->root();
executed (the execution status of this line is deduced): Base *base = header->root();
-
68 int reserve = 0;
executed (the execution status of this line is deduced): int reserve = 0;
-
69 if (base->is_object) {
evaluated: base->is_object
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:3
3-5
70 Object *o = static_cast<Object *>(base);
executed (the execution status of this line is deduced): Object *o = static_cast<Object *>(base);
-
71 for (int i = 0; i < (int)o->length; ++i)
evaluated: i < (int)o->length
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:5
5-7
72 reserve += o->entryAt(i)->usedStorage(o);
executed: reserve += o->entryAt(i)->usedStorage(o);
Execution Count:7
7
73 } else {
executed: }
Execution Count:5
5
74 Array *a = static_cast<Array *>(base);
executed (the execution status of this line is deduced): Array *a = static_cast<Array *>(base);
-
75 for (int i = 0; i < (int)a->length; ++i)
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
76 reserve += (*a)[i].usedStorage(a);
executed: reserve += (*a)[i].usedStorage(a);
Execution Count:3
3
77 }
executed: }
Execution Count:3
3
78 -
79 int size = sizeof(Base) + reserve + base->length*sizeof(offset);
executed (the execution status of this line is deduced): int size = sizeof(Base) + reserve + base->length*sizeof(offset);
-
80 int alloc = sizeof(Header) + size;
executed (the execution status of this line is deduced): int alloc = sizeof(Header) + size;
-
81 Header *h = (Header *) malloc(alloc);
executed (the execution status of this line is deduced): Header *h = (Header *) malloc(alloc);
-
82 h->tag = QJsonDocument::BinaryFormatTag;
executed (the execution status of this line is deduced): h->tag = QJsonDocument::BinaryFormatTag;
-
83 h->version = 1;
executed (the execution status of this line is deduced): h->version = 1;
-
84 Base *b = h->root();
executed (the execution status of this line is deduced): Base *b = h->root();
-
85 b->size = size;
executed (the execution status of this line is deduced): b->size = size;
-
86 b->is_object = header->root()->is_object;
executed (the execution status of this line is deduced): b->is_object = header->root()->is_object;
-
87 b->length = base->length;
executed (the execution status of this line is deduced): b->length = base->length;
-
88 b->tableOffset = reserve + sizeof(Array);
executed (the execution status of this line is deduced): b->tableOffset = reserve + sizeof(Array);
-
89 -
90 int offset = sizeof(Base);
executed (the execution status of this line is deduced): int offset = sizeof(Base);
-
91 if (b->is_object) {
evaluated: b->is_object
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:3
3-5
92 Object *o = static_cast<Object *>(base);
executed (the execution status of this line is deduced): Object *o = static_cast<Object *>(base);
-
93 Object *no = static_cast<Object *>(b);
executed (the execution status of this line is deduced): Object *no = static_cast<Object *>(b);
-
94 -
95 for (int i = 0; i < (int)o->length; ++i) {
evaluated: i < (int)o->length
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:5
5-7
96 no->table()[i] = offset;
executed (the execution status of this line is deduced): no->table()[i] = offset;
-
97 -
98 const Entry *e = o->entryAt(i);
executed (the execution status of this line is deduced): const Entry *e = o->entryAt(i);
-
99 Entry *ne = no->entryAt(i);
executed (the execution status of this line is deduced): Entry *ne = no->entryAt(i);
-
100 int s = e->size();
executed (the execution status of this line is deduced): int s = e->size();
-
101 memcpy(ne, e, s);
executed (the execution status of this line is deduced): memcpy(ne, e, s);
-
102 offset += s;
executed (the execution status of this line is deduced): offset += s;
-
103 int dataSize = e->value.usedStorage(o);
executed (the execution status of this line is deduced): int dataSize = e->value.usedStorage(o);
-
104 if (dataSize) {
partially evaluated: dataSize
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
105 memcpy((char *)no + offset, e->value.data(o), dataSize);
executed (the execution status of this line is deduced): memcpy((char *)no + offset, e->value.data(o), dataSize);
-
106 ne->value.value = offset;
executed (the execution status of this line is deduced): ne->value.value = offset;
-
107 offset += dataSize;
executed (the execution status of this line is deduced): offset += dataSize;
-
108 }
executed: }
Execution Count:7
7
109 }
executed: }
Execution Count:7
7
110 } else {
executed: }
Execution Count:5
5
111 Array *a = static_cast<Array *>(base);
executed (the execution status of this line is deduced): Array *a = static_cast<Array *>(base);
-
112 Array *na = static_cast<Array *>(b);
executed (the execution status of this line is deduced): Array *na = static_cast<Array *>(b);
-
113 -
114 for (int i = 0; i < (int)a->length; ++i) {
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
115 const Value &v = (*a)[i];
executed (the execution status of this line is deduced): const Value &v = (*a)[i];
-
116 Value &nv = (*na)[i];
executed (the execution status of this line is deduced): Value &nv = (*na)[i];
-
117 nv = v;
executed (the execution status of this line is deduced): nv = v;
-
118 int dataSize = v.usedStorage(a);
executed (the execution status of this line is deduced): int dataSize = v.usedStorage(a);
-
119 if (dataSize) {
partially evaluated: dataSize
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
120 memcpy((char *)na + offset, v.data(a), dataSize);
executed (the execution status of this line is deduced): memcpy((char *)na + offset, v.data(a), dataSize);
-
121 nv.value = offset;
executed (the execution status of this line is deduced): nv.value = offset;
-
122 offset += dataSize;
executed (the execution status of this line is deduced): offset += dataSize;
-
123 }
executed: }
Execution Count:3
3
124 }
executed: }
Execution Count:3
3
125 }
executed: }
Execution Count:3
3
126 Q_ASSERT(offset == (int)b->tableOffset);
executed (the execution status of this line is deduced): qt_noop();
-
127 -
128 free(header);
executed (the execution status of this line is deduced): free(header);
-
129 header = h;
executed (the execution status of this line is deduced): header = h;
-
130 this->alloc = alloc;
executed (the execution status of this line is deduced): this->alloc = alloc;
-
131 compactionCounter = 0;
executed (the execution status of this line is deduced): compactionCounter = 0;
-
132}
executed: }
Execution Count:8
8
133 -
134bool Data::valid() const -
135{ -
136 if (header->tag != QJsonDocument::BinaryFormatTag || header->version != 1u)
partially evaluated: header->tag != QJsonDocument::BinaryFormatTag
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1857
partially evaluated: header->version != 1u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1857
0-1857
137 return false;
never executed: return false;
0
138 -
139 bool res = false;
executed (the execution status of this line is deduced): bool res = false;
-
140 if (header->root()->is_object)
evaluated: header->root()->is_object
TRUEFALSE
yes
Evaluation Count:867
yes
Evaluation Count:990
867-990
141 res = static_cast<Object *>(header->root())->isValid();
executed: res = static_cast<Object *>(header->root())->isValid();
Execution Count:867
867
142 else -
143 res = static_cast<Array *>(header->root())->isValid();
executed: res = static_cast<Array *>(header->root())->isValid();
Execution Count:990
990
144 -
145 return res;
executed: return res;
Execution Count:1857
1857
146} -
147 -
148 -
149int Base::reserveSpace(uint dataSize, int posInTable, uint numItems, bool replace) -
150{ -
151 Q_ASSERT(posInTable >= 0 && posInTable <= (int)length);
executed (the execution status of this line is deduced): qt_noop();
-
152 -
153 offset off = tableOffset;
executed (the execution status of this line is deduced): offset off = tableOffset;
-
154 // move table to new position -
155 if (replace) {
evaluated: replace
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:249
97-249
156 memmove((char *)(table()) + dataSize, table(), length*sizeof(offset));
executed (the execution status of this line is deduced): memmove((char *)(table()) + dataSize, table(), length*sizeof(offset));
-
157 } else {
executed: }
Execution Count:97
97
158 memmove((char *)(table() + posInTable + numItems) + dataSize, table() + posInTable, (length - posInTable)*sizeof(offset));
executed (the execution status of this line is deduced): memmove((char *)(table() + posInTable + numItems) + dataSize, table() + posInTable, (length - posInTable)*sizeof(offset));
-
159 memmove((char *)(table()) + dataSize, table(), posInTable*sizeof(offset));
executed (the execution status of this line is deduced): memmove((char *)(table()) + dataSize, table(), posInTable*sizeof(offset));
-
160 }
executed: }
Execution Count:249
249
161 tableOffset += dataSize;
executed (the execution status of this line is deduced): tableOffset += dataSize;
-
162 for (int i = 0; i < (int)numItems; ++i)
evaluated: i < (int)numItems
TRUEFALSE
yes
Evaluation Count:346
yes
Evaluation Count:346
346
163 table()[posInTable + i] = off;
executed: table()[posInTable + i] = off;
Execution Count:346
346
164 size += dataSize;
executed (the execution status of this line is deduced): size += dataSize;
-
165 if (!replace) {
evaluated: !replace
TRUEFALSE
yes
Evaluation Count:249
yes
Evaluation Count:97
97-249
166 length += numItems;
executed (the execution status of this line is deduced): length += numItems;
-
167 size += numItems * sizeof(offset);
executed (the execution status of this line is deduced): size += numItems * sizeof(offset);
-
168 }
executed: }
Execution Count:249
249
169 return off;
executed: return off;
Execution Count:346
346
170} -
171 -
172void Base::removeItems(int pos, int numItems) -
173{ -
174 Q_ASSERT(pos >= 0 && pos <= (int)length);
executed (the execution status of this line is deduced): qt_noop();
-
175 if (pos + numItems < (int)length)
evaluated: pos + numItems < (int)length
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:43
30-43
176 memmove(table() + pos, table() + pos + numItems, (length - pos - numItems)*sizeof(offset));
executed: memmove(table() + pos, table() + pos + numItems, (length - pos - numItems)*sizeof(offset));
Execution Count:30
30
177 length -= numItems;
executed (the execution status of this line is deduced): length -= numItems;
-
178}
executed: }
Execution Count:73
73
179 -
180int Object::indexOf(const QString &key, bool *exists) -
181{ -
182 int min = 0;
executed (the execution status of this line is deduced): int min = 0;
-
183 int n = length;
executed (the execution status of this line is deduced): int n = length;
-
184 while (n > 0) {
evaluated: n > 0
TRUEFALSE
yes
Evaluation Count:60569
yes
Evaluation Count:28818
28818-60569
185 int half = n >> 1;
executed (the execution status of this line is deduced): int half = n >> 1;
-
186 int middle = min + half;
executed (the execution status of this line is deduced): int middle = min + half;
-
187 if (*entryAt(middle) >= key) {
evaluated: *entryAt(middle) >= key
TRUEFALSE
yes
Evaluation Count:43560
yes
Evaluation Count:17009
17009-43560
188 n = half;
executed (the execution status of this line is deduced): n = half;
-
189 } else {
executed: }
Execution Count:43560
43560
190 min = middle + 1;
executed (the execution status of this line is deduced): min = middle + 1;
-
191 n -= half + 1;
executed (the execution status of this line is deduced): n -= half + 1;
-
192 }
executed: }
Execution Count:17009
17009
193 } -
194 if (min < (int)length && *entryAt(min) == key) {
evaluated: min < (int)length
TRUEFALSE
yes
Evaluation Count:28675
yes
Evaluation Count:143
evaluated: *entryAt(min) == key
TRUEFALSE
yes
Evaluation Count:28505
yes
Evaluation Count:170
143-28675
195 *exists = true;
executed (the execution status of this line is deduced): *exists = true;
-
196 return min;
executed: return min;
Execution Count:28505
28505
197 } -
198 *exists = false;
executed (the execution status of this line is deduced): *exists = false;
-
199 return min;
executed: return min;
Execution Count:313
313
200} -
201 -
202bool Object::isValid() const -
203{ -
204 if (tableOffset + length*sizeof(offset) > size)
evaluated: tableOffset + length*sizeof(offset) > size
TRUEFALSE
yes
Evaluation Count:65
yes
Evaluation Count:322817
65-322817
205 return false;
executed: return false;
Execution Count:65
65
206 -
207 for (uint i = 0; i < length; ++i) {
evaluated: i < length
TRUEFALSE
yes
Evaluation Count:992716
yes
Evaluation Count:322327
322327-992716
208 offset entryOffset = table()[i];
executed (the execution status of this line is deduced): offset entryOffset = table()[i];
-
209 if (entryOffset + sizeof(Entry) >= tableOffset)
evaluated: entryOffset + sizeof(Entry) >= tableOffset
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:992665
51-992665
210 return false;
executed: return false;
Execution Count:51
51
211 Entry *e = entryAt(i);
executed (the execution status of this line is deduced): Entry *e = entryAt(i);
-
212 int s = e->size();
executed (the execution status of this line is deduced): int s = e->size();
-
213 if (table()[i] + s > tableOffset)
evaluated: table()[i] + s > tableOffset
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:992590
75-992590
214 return false;
executed: return false;
Execution Count:75
75
215 if (!e->value.isValid(this))
evaluated: !e->value.isValid(this)
TRUEFALSE
yes
Evaluation Count:364
yes
Evaluation Count:992226
364-992226
216 return false;
executed: return false;
Execution Count:364
364
217 }
executed: }
Execution Count:992226
992226
218 return true;
executed: return true;
Execution Count:322327
322327
219} -
220 -
221 -
222 -
223bool Array::isValid() const -
224{ -
225 if (tableOffset + length*sizeof(offset) > size)
evaluated: tableOffset + length*sizeof(offset) > size
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:38617
55-38617
226 return false;
executed: return false;
Execution Count:55
55
227 -
228 for (uint i = 0; i < length; ++i) {
evaluated: i < length
TRUEFALSE
yes
Evaluation Count:182122
yes
Evaluation Count:38289
38289-182122
229 if (!at(i).isValid(this))
evaluated: !at(i).isValid(this)
TRUEFALSE
yes
Evaluation Count:328
yes
Evaluation Count:181794
328-181794
230 return false;
executed: return false;
Execution Count:328
328
231 }
executed: }
Execution Count:181794
181794
232 return true;
executed: return true;
Execution Count:38289
38289
233} -
234 -
235 -
236bool Entry::operator ==(const QString &key) const -
237{ -
238 if (value.latinKey)
evaluated: value.latinKey
TRUEFALSE
yes
Evaluation Count:28672
yes
Evaluation Count:3
3-28672
239 return (shallowLatin1Key() == key);
executed: return (shallowLatin1Key() == key);
Execution Count:28672
28672
240 else -
241 return (shallowKey() == key);
executed: return (shallowKey() == key);
Execution Count:3
3
242} -
243 -
244bool Entry::operator ==(const Entry &other) const -
245{ -
246 if (value.latinKey) {
partially evaluated: value.latinKey
TRUEFALSE
yes
Evaluation Count:2442
no
Evaluation Count:0
0-2442
247 if (other.value.latinKey)
evaluated: other.value.latinKey
TRUEFALSE
yes
Evaluation Count:2438
yes
Evaluation Count:4
4-2438
248 return shallowLatin1Key() == other.shallowLatin1Key();
executed: return shallowLatin1Key() == other.shallowLatin1Key();
Execution Count:2438
2438
249 return shallowLatin1Key() == other.shallowKey();
executed: return shallowLatin1Key() == other.shallowKey();
Execution Count:4
4
250 } else if (other.value.latinKey) {
never evaluated: other.value.latinKey
0
251 return shallowKey() == other.shallowLatin1Key();
never executed: return shallowKey() == other.shallowLatin1Key();
0
252 } -
253 return shallowKey() == other.shallowKey();
never executed: return shallowKey() == other.shallowKey();
0
254} -
255 -
256bool Entry::operator >=(const Entry &other) const -
257{ -
258 if (value.latinKey) {
partially evaluated: value.latinKey
TRUEFALSE
yes
Evaluation Count:7317
no
Evaluation Count:0
0-7317
259 if (other.value.latinKey)
evaluated: other.value.latinKey
TRUEFALSE
yes
Evaluation Count:7297
yes
Evaluation Count:20
20-7297
260 return shallowLatin1Key() >= other.shallowLatin1Key();
executed: return shallowLatin1Key() >= other.shallowLatin1Key();
Execution Count:7297
7297
261 return shallowLatin1Key() >= other.shallowKey();
executed: return shallowLatin1Key() >= other.shallowKey();
Execution Count:20
20
262 } else if (other.value.latinKey) {
never evaluated: other.value.latinKey
0
263 return shallowKey() >= other.shallowLatin1Key();
never executed: return shallowKey() >= other.shallowLatin1Key();
0
264 } -
265 return shallowKey() >= other.shallowKey();
never executed: return shallowKey() >= other.shallowKey();
0
266} -
267 -
268 -
269int Value::usedStorage(const Base *b) const -
270{ -
271 int s = 0;
executed (the execution status of this line is deduced): int s = 0;
-
272 switch (type) { -
273 case QJsonValue::Double: -
274 if (latinOrIntValue)
partially evaluated: latinOrIntValue
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69828
0-69828
275 break;
never executed: break;
0
276 s = sizeof(double);
executed (the execution status of this line is deduced): s = sizeof(double);
-
277 break;
executed: break;
Execution Count:69828
69828
278 case QJsonValue::String: { -
279 char *d = data(b);
executed (the execution status of this line is deduced): char *d = data(b);
-
280 if (latinOrIntValue)
evaluated: latinOrIntValue
TRUEFALSE
yes
Evaluation Count:353880
yes
Evaluation Count:804
804-353880
281 s = sizeof(ushort) + qFromLittleEndian(*(ushort *)d);
executed: s = sizeof(ushort) + qFromLittleEndian(*(ushort *)d);
Execution Count:353880
353880
282 else -
283 s = sizeof(int) + sizeof(ushort) * qFromLittleEndian(*(int *)d);
executed: s = sizeof(int) + sizeof(ushort) * qFromLittleEndian(*(int *)d);
Execution Count:804
804
284 break;
executed: break;
Execution Count:354684
354684
285 } -
286 case QJsonValue::Array: -
287 case QJsonValue::Object: -
288 s = base(b)->size;
executed (the execution status of this line is deduced): s = base(b)->size;
-
289 break;
executed: break;
Execution Count:359743
359743
290 case QJsonValue::Null: -
291 case QJsonValue::Bool: -
292 default: -
293 break;
never executed: break;
0
294 } -
295 return alignedSize(s);
executed: return alignedSize(s);
Execution Count:784255
784255
296} -
297 -
298bool Value::isValid(const Base *b) const -
299{ -
300 int offset = 0;
executed (the execution status of this line is deduced): int offset = 0;
-
301 switch (type) { -
302 case QJsonValue::Double: -
303 if (latinOrIntValue)
evaluated: latinOrIntValue
TRUEFALSE
yes
Evaluation Count:384942
yes
Evaluation Count:69843
69843-384942
304 break;
executed: break;
Execution Count:384942
384942
305 // fall through -
306 case QJsonValue::String:
code before this statement executed: case QJsonValue::String:
Execution Count:69843
69843
307 case QJsonValue::Array: -
308 case QJsonValue::Object: -
309 offset = value;
executed (the execution status of this line is deduced): offset = value;
-
310 break;
executed: break;
Execution Count:784361
784361
311 case QJsonValue::Null: -
312 case QJsonValue::Bool: -
313 default: -
314 break;
executed: break;
Execution Count:5409
5409
315 } -
316 -
317 if (!offset)
evaluated: !offset
TRUEFALSE
yes
Evaluation Count:390351
yes
Evaluation Count:784361
390351-784361
318 return true;
executed: return true;
Execution Count:390351
390351
319 if (offset + sizeof(uint) > b->tableOffset)
evaluated: offset + sizeof(uint) > b->tableOffset
TRUEFALSE
yes
Evaluation Count:126
yes
Evaluation Count:784235
126-784235
320 return false;
executed: return false;
Execution Count:126
126
321 -
322 int s = usedStorage(b);
executed (the execution status of this line is deduced): int s = usedStorage(b);
-
323 if (!s)
evaluated: !s
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:784234
1-784234
324 return true;
executed: return true;
Execution Count:1
1
325 if (s < 0 || offset + s > (int)b->tableOffset)
evaluated: s < 0
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:784220
evaluated: offset + s > (int)b->tableOffset
TRUEFALSE
yes
Evaluation Count:69
yes
Evaluation Count:784151
14-784220
326 return false;
executed: return false;
Execution Count:83
83
327 if (type == QJsonValue::Array)
evaluated: type == QJsonValue::Array
TRUEFALSE
yes
Evaluation Count:37682
yes
Evaluation Count:746469
37682-746469
328 return static_cast<Array *>(base(b))->isValid();
executed: return static_cast<Array *>(base(b))->isValid();
Execution Count:37682
37682
329 if (type == QJsonValue::Object)
evaluated: type == QJsonValue::Object
TRUEFALSE
yes
Evaluation Count:322015
yes
Evaluation Count:424454
322015-424454
330 return static_cast<Object *>(base(b))->isValid();
executed: return static_cast<Object *>(base(b))->isValid();
Execution Count:322015
322015
331 return true;
executed: return true;
Execution Count:424454
424454
332} -
333 -
334/*! -
335 \internal -
336 */ -
337int Value::requiredStorage(const QJsonValue &v, bool *compressed) -
338{ -
339 *compressed = false;
executed (the execution status of this line is deduced): *compressed = false;
-
340 switch (v.t) { -
341 case QJsonValue::Double: -
342 if (QJsonPrivate::compressedNumber(v.dbl) != INT_MAX) {
evaluated: QJsonPrivate::compressedNumber(v.dbl) != 2147483647
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:34
34-81
343 *compressed = true;
executed (the execution status of this line is deduced): *compressed = true;
-
344 return 0;
executed: return 0;
Execution Count:81
81
345 } -
346 return sizeof(double);
executed: return sizeof(double);
Execution Count:34
34
347 case QJsonValue::String: { -
348 QString s = v.toString();
executed (the execution status of this line is deduced): QString s = v.toString();
-
349 *compressed = QJsonPrivate::useCompressed(s);
executed (the execution status of this line is deduced): *compressed = QJsonPrivate::useCompressed(s);
-
350 return QJsonPrivate::qStringSize(s, *compressed);
executed: return QJsonPrivate::qStringSize(s, *compressed);
Execution Count:153
153
351 } -
352 case QJsonValue::Array: -
353 case QJsonValue::Object: -
354 return v.base ? v.base->size : sizeof(QJsonPrivate::Base);
executed: return v.base ? v.base->size : sizeof(QJsonPrivate::Base);
Execution Count:22
22
355 case QJsonValue::Undefined: -
356 case QJsonValue::Null: -
357 case QJsonValue::Bool: -
358 break;
executed: break;
Execution Count:56
56
359 } -
360 return 0;
executed: return 0;
Execution Count:56
56
361} -
362 -
363/*! -
364 \internal -
365 */ -
366uint Value::valueToStore(const QJsonValue &v, uint offset) -
367{ -
368 switch (v.t) { -
369 case QJsonValue::Undefined: -
370 case QJsonValue::Null: -
371 break;
executed: break;
Execution Count:37
37
372 case QJsonValue::Bool: -
373 return v.b;
executed: return v.b;
Execution Count:19
19
374 case QJsonValue::Double: { -
375 int c = QJsonPrivate::compressedNumber(v.dbl);
executed (the execution status of this line is deduced): int c = QJsonPrivate::compressedNumber(v.dbl);
-
376 if (c != INT_MAX)
evaluated: c != 2147483647
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:34
34-81
377 return c;
executed: return c;
Execution Count:81
81
378 } -
379 // fall through -
380 case QJsonValue::String: -
381 case QJsonValue::Array: -
382 case QJsonValue::Object: -
383 return offset;
executed: return offset;
Execution Count:209
209
384 } -
385 return 0;
executed: return 0;
Execution Count:37
37
386} -
387 -
388/*! -
389 \internal -
390 */ -
391void Value::copyData(const QJsonValue &v, char *dest, bool compressed) -
392{ -
393 switch (v.t) { -
394 case QJsonValue::Double: -
395 if (!compressed) {
partially evaluated: !compressed
TRUEFALSE
yes
Evaluation Count:34
no
Evaluation Count:0
0-34
396 qToLittleEndian(v.ui, (uchar *)dest);
executed (the execution status of this line is deduced): qToLittleEndian(v.ui, (uchar *)dest);
-
397 }
executed: }
Execution Count:34
34
398 break;
executed: break;
Execution Count:34
34
399 case QJsonValue::String: { -
400 QString str = v.toString();
executed (the execution status of this line is deduced): QString str = v.toString();
-
401 QJsonPrivate::copyString(dest, str, compressed);
executed (the execution status of this line is deduced): QJsonPrivate::copyString(dest, str, compressed);
-
402 break;
executed: break;
Execution Count:153
153
403 } -
404 case QJsonValue::Array: -
405 case QJsonValue::Object: { -
406 const QJsonPrivate::Base *b = v.base;
executed (the execution status of this line is deduced): const QJsonPrivate::Base *b = v.base;
-
407 if (!b)
evaluated: !b
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:17
5-17
408 b = (v.t == QJsonValue::Array ? &emptyArray : &emptyObject);
executed: b = (v.t == QJsonValue::Array ? &emptyArray : &emptyObject);
Execution Count:5
evaluated: v.t == QJsonValue::Array
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-5
409 memcpy(dest, b, b->size);
executed (the execution status of this line is deduced): memcpy(dest, b, b->size);
-
410 break;
executed: break;
Execution Count:22
22
411 } -
412 default: -
413 break;
never executed: break;
0
414 } -
415}
executed: }
Execution Count:209
209
416 -
417} // namespace QJsonPrivate -
418 -
419QT_END_NAMESPACE -
420 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial