| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | QJsonObject::QJsonObject() | - |
| 4 | : d(0), o(0) | - |
| 5 | { | - |
| 6 | } executed: }Execution Count:12178 | 12178 |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object) | - |
| 12 | : d(data), o(object) | - |
| 13 | { | - |
| 14 | qt_noop(); | - |
| 15 | qt_noop(); | - |
| 16 | d->ref.ref(); | - |
| 17 | } executed: }Execution Count:15208 | 15208 |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | QJsonObject::~QJsonObject() | - |
| 24 | { | - |
| 25 | if (d && !d->ref.deref()) evaluated: d| yes Evaluation Count:28290 | yes Evaluation Count:12051 |
evaluated: !d->ref.deref()| yes Evaluation Count:1947 | yes Evaluation Count:26343 |
| 1947-28290 |
| 26 | delete d; executed: delete d;Execution Count:1947 | 1947 |
| 27 | } executed: }Execution Count:40341 | 40341 |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | QJsonObject::QJsonObject(const QJsonObject &other) | - |
| 36 | { | - |
| 37 | d = other.d; | - |
| 38 | o = other.o; | - |
| 39 | if (d) evaluated: d| yes Evaluation Count:11148 | yes Evaluation Count:8 |
| 8-11148 |
| 40 | d->ref.ref(); executed: d->ref.ref();Execution Count:11148 | 11148 |
| 41 | } executed: }Execution Count:11156 | 11156 |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | QJsonObject &QJsonObject::operator =(const QJsonObject &other) | - |
| 47 | { | - |
| 48 | if (d != other.d) { evaluated: d != other.d| yes Evaluation Count:229 | yes Evaluation Count:3 |
| 3-229 |
| 49 | if (d && !d->ref.deref()) evaluated: d| yes Evaluation Count:1 | yes Evaluation Count:228 |
partially evaluated: !d->ref.deref()| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-228 |
| 50 | delete d; executed: delete d;Execution Count:1 | 1 |
| 51 | d = other.d; | - |
| 52 | if (d) partially evaluated: d| yes Evaluation Count:229 | no Evaluation Count:0 |
| 0-229 |
| 53 | d->ref.ref(); executed: d->ref.ref();Execution Count:229 | 229 |
| 54 | } executed: }Execution Count:229 | 229 |
| 55 | o = other.o; | - |
| 56 | | - |
| 57 | return *this; executed: return *this;Execution Count:232 | 232 |
| 58 | } | - |
| 59 | QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) | - |
| 60 | { | - |
| 61 | | - |
| 62 | | - |
| 63 | QJsonObject object; | - |
| 64 | for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) evaluated: it != map.constEnd()| yes Evaluation Count:5 | yes Evaluation Count:2 |
| 2-5 |
| 65 | object.insert(it.key(), QJsonValue::fromVariant(it.value())); executed: object.insert(it.key(), QJsonValue::fromVariant(it.value()));Execution Count:5 | 5 |
| 66 | return object; executed: return object;Execution Count:2 | 2 |
| 67 | } | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | QVariantMap QJsonObject::toVariantMap() const | - |
| 75 | { | - |
| 76 | QVariantMap map; | - |
| 77 | if (o) { evaluated: o| yes Evaluation Count:867 | yes Evaluation Count:1 |
| 1-867 |
| 78 | for (uint i = 0; i < o->length; ++i) { evaluated: i < o->length| yes Evaluation Count:2663 | yes Evaluation Count:867 |
| 867-2663 |
| 79 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 80 | map.insert(e->key(), QJsonValue(d, o, e->value).toVariant()); | - |
| 81 | } executed: }Execution Count:2663 | 2663 |
| 82 | } executed: }Execution Count:867 | 867 |
| 83 | return map; executed: return map;Execution Count:868 | 868 |
| 84 | } | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | QStringList QJsonObject::keys() const | - |
| 90 | { | - |
| 91 | if (!d) evaluated: !d| yes Evaluation Count:1 | yes Evaluation Count:5 |
| 1-5 |
| 92 | return QStringList(); executed: return QStringList();Execution Count:1 | 1 |
| 93 | | - |
| 94 | QStringList keys; | - |
| 95 | | - |
| 96 | for (uint i = 0; i < o->length; ++i) { evaluated: i < o->length| yes Evaluation Count:6 | yes Evaluation Count:5 |
| 5-6 |
| 97 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 98 | keys.append(e->key()); | - |
| 99 | } executed: }Execution Count:6 | 6 |
| 100 | | - |
| 101 | return keys; executed: return keys;Execution Count:5 | 5 |
| 102 | } | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | int QJsonObject::size() const | - |
| 108 | { | - |
| 109 | if (!d) evaluated: !d| yes Evaluation Count:1 | yes Evaluation Count:63 |
| 1-63 |
| 110 | return 0; executed: return 0;Execution Count:1 | 1 |
| 111 | | - |
| 112 | return o->length; executed: return o->length;Execution Count:63 | 63 |
| 113 | } | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | bool QJsonObject::isEmpty() const | - |
| 121 | { | - |
| 122 | if (!d) partially evaluated: !d| no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
| 123 | return true; never executed: return true; | 0 |
| 124 | | - |
| 125 | return !o->length; executed: return !o->length;Execution Count:13 | 13 |
| 126 | } | - |
| 127 | QJsonValue QJsonObject::value(const QString &key) const | - |
| 128 | { | - |
| 129 | if (!d) evaluated: !d| yes Evaluation Count:1 | yes Evaluation Count:28515 |
| 1-28515 |
| 130 | return QJsonValue(); executed: return QJsonValue();Execution Count:1 | 1 |
| 131 | | - |
| 132 | bool keyExists; | - |
| 133 | int i = o->indexOf(key, &keyExists); | - |
| 134 | if (!keyExists) evaluated: !keyExists| yes Evaluation Count:160 | yes Evaluation Count:28355 |
| 160-28355 |
| 135 | return QJsonValue(QJsonValue::Undefined); executed: return QJsonValue(QJsonValue::Undefined);Execution Count:160 | 160 |
| 136 | return QJsonValue(d, o, o->entryAt(i)->value); executed: return QJsonValue(d, o, o->entryAt(i)->value);Execution Count:28355 | 28355 |
| 137 | } | - |
| 138 | QJsonValue QJsonObject::operator [](const QString &key) const | - |
| 139 | { | - |
| 140 | return value(key); never executed: return value(key); | 0 |
| 141 | } | - |
| 142 | QJsonValueRef QJsonObject::operator [](const QString &key) | - |
| 143 | { | - |
| 144 | | - |
| 145 | bool keyExists = false; | - |
| 146 | int index = o ? o->indexOf(key, &keyExists) : -1; evaluated: o| yes Evaluation Count:22 | yes Evaluation Count:3 |
| 3-22 |
| 147 | if (!keyExists) { evaluated: !keyExists| yes Evaluation Count:21 | yes Evaluation Count:4 |
| 4-21 |
| 148 | iterator i = insert(key, QJsonValue()); | - |
| 149 | index = i.i; | - |
| 150 | } executed: }Execution Count:21 | 21 |
| 151 | return QJsonValueRef(this, index); executed: return QJsonValueRef(this, index);Execution Count:25 | 25 |
| 152 | } | - |
| 153 | QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) | - |
| 154 | { | - |
| 155 | if (value.t == QJsonValue::Undefined) { evaluated: value.t == QJsonValue::Undefined| yes Evaluation Count:2 | yes Evaluation Count:220 |
| 2-220 |
| 156 | remove(key); | - |
| 157 | return end(); executed: return end();Execution Count:2 | 2 |
| 158 | } | - |
| 159 | | - |
| 160 | bool latinOrIntValue; | - |
| 161 | int valueSize = QJsonPrivate::Value::requiredStorage(value, &latinOrIntValue); | - |
| 162 | | - |
| 163 | bool latinKey = QJsonPrivate::useCompressed(key); | - |
| 164 | int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey); | - |
| 165 | int requiredSize = valueOffset + valueSize; | - |
| 166 | | - |
| 167 | detach(requiredSize + sizeof(QJsonPrivate::offset)); | - |
| 168 | | - |
| 169 | if (!o->length) evaluated: !o->length| yes Evaluation Count:71 | yes Evaluation Count:149 |
| 71-149 |
| 170 | o->tableOffset = sizeof(QJsonPrivate::Object); executed: o->tableOffset = sizeof(QJsonPrivate::Object);Execution Count:71 | 71 |
| 171 | | - |
| 172 | bool keyExists = false; | - |
| 173 | int pos = o->indexOf(key, &keyExists); | - |
| 174 | if (keyExists) evaluated: keyExists| yes Evaluation Count:93 | yes Evaluation Count:127 |
| 93-127 |
| 175 | ++d->compactionCounter; executed: ++d->compactionCounter;Execution Count:93 | 93 |
| 176 | | - |
| 177 | o->reserveSpace(requiredSize, pos, 1, keyExists); | - |
| 178 | | - |
| 179 | QJsonPrivate::Entry *e = o->entryAt(pos); | - |
| 180 | e->value.type = value.t; | - |
| 181 | e->value.latinKey = latinKey; | - |
| 182 | e->value.latinOrIntValue = latinOrIntValue; | - |
| 183 | e->value.value = QJsonPrivate::Value::valueToStore(value, (char *)e - (char *)o + valueOffset); | - |
| 184 | QJsonPrivate::copyString((char *)(e + 1), key, latinKey); | - |
| 185 | if (valueSize) evaluated: valueSize| yes Evaluation Count:152 | yes Evaluation Count:68 |
| 68-152 |
| 186 | QJsonPrivate::Value::copyData(value, (char *)e + valueOffset, latinOrIntValue); executed: QJsonPrivate::Value::copyData(value, (char *)e + valueOffset, latinOrIntValue);Execution Count:152 | 152 |
| 187 | | - |
| 188 | return iterator(this, pos); executed: return iterator(this, pos);Execution Count:220 | 220 |
| 189 | } | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | | - |
| 194 | | - |
| 195 | | - |
| 196 | void QJsonObject::remove(const QString &key) | - |
| 197 | { | - |
| 198 | if (!d) evaluated: !d| yes Evaluation Count:3 | yes Evaluation Count:44 |
| 3-44 |
| 199 | return; executed: return;Execution Count:3 | 3 |
| 200 | | - |
| 201 | bool keyExists; | - |
| 202 | int index = o->indexOf(key, &keyExists); | - |
| 203 | if (!keyExists) evaluated: !keyExists| yes Evaluation Count:2 | yes Evaluation Count:42 |
| 2-42 |
| 204 | return; executed: return;Execution Count:2 | 2 |
| 205 | | - |
| 206 | detach(); | - |
| 207 | o->removeItems(index, 1); | - |
| 208 | ++d->compactionCounter; | - |
| 209 | if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u) partially evaluated: d->compactionCounter > 32u| no Evaluation Count:0 | yes Evaluation Count:42 |
never evaluated: d->compactionCounter >= unsigned(o->length) / 2u | 0-42 |
| 210 | compact(); never executed: compact(); | 0 |
| 211 | } executed: }Execution Count:42 | 42 |
| 212 | QJsonValue QJsonObject::take(const QString &key) | - |
| 213 | { | - |
| 214 | if (!o) evaluated: !o| yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
| 215 | return QJsonValue(QJsonValue::Undefined); executed: return QJsonValue(QJsonValue::Undefined);Execution Count:1 | 1 |
| 216 | | - |
| 217 | bool keyExists; | - |
| 218 | int index = o->indexOf(key, &keyExists); | - |
| 219 | if (!keyExists) evaluated: !keyExists| yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
| 220 | return QJsonValue(QJsonValue::Undefined); executed: return QJsonValue(QJsonValue::Undefined);Execution Count:1 | 1 |
| 221 | | - |
| 222 | QJsonValue v(d, o, o->entryAt(index)->value); | - |
| 223 | detach(); | - |
| 224 | o->removeItems(index, 1); | - |
| 225 | ++d->compactionCounter; | - |
| 226 | if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u) partially evaluated: d->compactionCounter > 32u| no Evaluation Count:0 | yes Evaluation Count:2 |
never evaluated: d->compactionCounter >= unsigned(o->length) / 2u | 0-2 |
| 227 | compact(); never executed: compact(); | 0 |
| 228 | | - |
| 229 | return v; executed: return v;Execution Count:2 | 2 |
| 230 | } | - |
| 231 | | - |
| 232 | | - |
| 233 | | - |
| 234 | | - |
| 235 | | - |
| 236 | | - |
| 237 | bool QJsonObject::contains(const QString &key) const | - |
| 238 | { | - |
| 239 | if (!o) evaluated: !o| yes Evaluation Count:1 | yes Evaluation Count:9 |
| 1-9 |
| 240 | return false; executed: return false;Execution Count:1 | 1 |
| 241 | | - |
| 242 | bool keyExists; | - |
| 243 | o->indexOf(key, &keyExists); | - |
| 244 | return keyExists; executed: return keyExists;Execution Count:9 | 9 |
| 245 | } | - |
| 246 | | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | bool QJsonObject::operator==(const QJsonObject &other) const | - |
| 251 | { | - |
| 252 | if (o == other.o) evaluated: o == other.o| yes Evaluation Count:21 | yes Evaluation Count:1313 |
| 21-1313 |
| 253 | return true; executed: return true;Execution Count:21 | 21 |
| 254 | | - |
| 255 | if (!o) evaluated: !o| yes Evaluation Count:1 | yes Evaluation Count:1312 |
| 1-1312 |
| 256 | return !other.o->length; executed: return !other.o->length;Execution Count:1 | 1 |
| 257 | if (!other.o) evaluated: !other.o| yes Evaluation Count:3 | yes Evaluation Count:1309 |
| 3-1309 |
| 258 | return !o->length; executed: return !o->length;Execution Count:3 | 3 |
| 259 | if (o->length != other.o->length) evaluated: o->length != other.o->length| yes Evaluation Count:1 | yes Evaluation Count:1308 |
| 1-1308 |
| 260 | return false; executed: return false;Execution Count:1 | 1 |
| 261 | | - |
| 262 | for (uint i = 0; i < o->length; ++i) { evaluated: i < o->length| yes Evaluation Count:4001 | yes Evaluation Count:1307 |
| 1307-4001 |
| 263 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 264 | QJsonValue v(d, o, e->value); | - |
| 265 | if (other.value(e->key()) != v) evaluated: other.value(e->key()) != v| yes Evaluation Count:1 | yes Evaluation Count:4000 |
| 1-4000 |
| 266 | return false; executed: return false;Execution Count:1 | 1 |
| 267 | } executed: }Execution Count:4000 | 4000 |
| 268 | | - |
| 269 | return true; executed: return true;Execution Count:1307 | 1307 |
| 270 | } | - |
| 271 | | - |
| 272 | | - |
| 273 | | - |
| 274 | | - |
| 275 | bool QJsonObject::operator!=(const QJsonObject &other) const | - |
| 276 | { | - |
| 277 | return !(*this == other); executed: return !(*this == other);Execution Count:3 | 3 |
| 278 | } | - |
| 279 | QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) | - |
| 280 | { | - |
| 281 | qt_noop(); | - |
| 282 | if (it.o != this || it.i < 0 || it.i >= (int)o->length) partially evaluated: it.o != this| no Evaluation Count:0 | yes Evaluation Count:12 |
partially evaluated: it.i < 0| no Evaluation Count:0 | yes Evaluation Count:12 |
partially evaluated: it.i >= (int)o->length| no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
| 283 | return iterator(this, o->length); never executed: return iterator(this, o->length); | 0 |
| 284 | | - |
| 285 | int index = it.i; | - |
| 286 | | - |
| 287 | o->removeItems(index, 1); | - |
| 288 | ++d->compactionCounter; | - |
| 289 | if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u) partially evaluated: d->compactionCounter > 32u| no Evaluation Count:0 | yes Evaluation Count:12 |
never evaluated: d->compactionCounter >= unsigned(o->length) / 2u | 0-12 |
| 290 | compact(); never executed: compact(); | 0 |
| 291 | | - |
| 292 | | - |
| 293 | return it; executed: return it;Execution Count:12 | 12 |
| 294 | } | - |
| 295 | QJsonObject::iterator QJsonObject::find(const QString &key) | - |
| 296 | { | - |
| 297 | bool keyExists = false; | - |
| 298 | int index = o ? o->indexOf(key, &keyExists) : 0; partially evaluated: o| yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
| 299 | if (!keyExists) evaluated: !keyExists| yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
| 300 | return end(); executed: return end();Execution Count:1 | 1 |
| 301 | detach(); | - |
| 302 | return iterator(this, index); executed: return iterator(this, index);Execution Count:2 | 2 |
| 303 | } | - |
| 304 | QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const | - |
| 305 | { | - |
| 306 | bool keyExists = false; | - |
| 307 | int index = o ? o->indexOf(key, &keyExists) : 0; partially evaluated: o| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
| 308 | if (!keyExists) evaluated: !keyExists| yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
| 309 | return end(); executed: return end();Execution Count:1 | 1 |
| 310 | return const_iterator(this, index); executed: return const_iterator(this, index);Execution Count:1 | 1 |
| 311 | } | - |
| 312 | void QJsonObject::detach(uint reserve) | - |
| 313 | { | - |
| 314 | if (!d) { evaluated: !d| yes Evaluation Count:38 | yes Evaluation Count:258 |
| 38-258 |
| 315 | d = new QJsonPrivate::Data(reserve, QJsonValue::Object); | - |
| 316 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - |
| 317 | d->ref.ref(); | - |
| 318 | return; executed: return;Execution Count:38 | 38 |
| 319 | } | - |
| 320 | if (reserve == 0 && d->ref.load() == 1) evaluated: reserve == 0| yes Evaluation Count:75 | yes Evaluation Count:183 |
evaluated: d->ref.load() == 1| yes Evaluation Count:61 | yes Evaluation Count:14 |
| 14-183 |
| 321 | return; executed: return;Execution Count:61 | 61 |
| 322 | | - |
| 323 | QJsonPrivate::Data *x = d->clone(o, reserve); | - |
| 324 | x->ref.ref(); | - |
| 325 | if (!d->ref.deref()) evaluated: !d->ref.deref()| yes Evaluation Count:36 | yes Evaluation Count:161 |
| 36-161 |
| 326 | delete d; executed: delete d;Execution Count:36 | 36 |
| 327 | d = x; | - |
| 328 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - |
| 329 | } executed: }Execution Count:197 | 197 |
| 330 | | - |
| 331 | | - |
| 332 | | - |
| 333 | | - |
| 334 | void QJsonObject::compact() | - |
| 335 | { | - |
| 336 | if (!d || !d->compactionCounter) partially evaluated: !d| no Evaluation Count:0 | yes Evaluation Count:5 |
partially evaluated: !d->compactionCounter| no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
| 337 | return; | 0 |
| 338 | | - |
| 339 | detach(); | - |
| 340 | d->compact(); | - |
| 341 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - |
| 342 | } executed: }Execution Count:5 | 5 |
| 343 | | - |
| 344 | | - |
| 345 | | - |
| 346 | | - |
| 347 | QString QJsonObject::keyAt(int i) const | - |
| 348 | { | - |
| 349 | qt_noop(); | - |
| 350 | | - |
| 351 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 352 | return e->key(); executed: return e->key();Execution Count:23 | 23 |
| 353 | } | - |
| 354 | | - |
| 355 | | - |
| 356 | | - |
| 357 | | - |
| 358 | QJsonValue QJsonObject::valueAt(int i) const | - |
| 359 | { | - |
| 360 | if (!o || i < 0 || i >= (int)o->length) partially evaluated: !o| no Evaluation Count:0 | yes Evaluation Count:46 |
partially evaluated: i < 0| no Evaluation Count:0 | yes Evaluation Count:46 |
evaluated: i >= (int)o->length| yes Evaluation Count:2 | yes Evaluation Count:44 |
| 0-46 |
| 361 | return QJsonValue(QJsonValue::Undefined); executed: return QJsonValue(QJsonValue::Undefined);Execution Count:2 | 2 |
| 362 | | - |
| 363 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 364 | return QJsonValue(d, o, e->value); executed: return QJsonValue(d, o, e->value);Execution Count:44 | 44 |
| 365 | } | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | void QJsonObject::setValueAt(int i, const QJsonValue &val) | - |
| 371 | { | - |
| 372 | qt_noop(); | - |
| 373 | | - |
| 374 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
| 375 | insert(e->key(), val); | - |
| 376 | } executed: }Execution Count:23 | 23 |
| 377 | | - |
| 378 | | - |
| 379 | QDebug operator<<(QDebug dbg, const QJsonObject &o) | - |
| 380 | { | - |
| 381 | if (!o.o) { evaluated: !o.o| yes Evaluation Count:2 | yes Evaluation Count:2 |
| 2 |
| 382 | dbg << "QJsonObject()"; | - |
| 383 | return dbg; executed: return dbg;Execution Count:2 | 2 |
| 384 | } | - |
| 385 | QByteArray json; | - |
| 386 | QJsonPrivate::Writer::objectToJson(o.o, json, 0, true); | - |
| 387 | dbg.nospace() << "QJsonObject(" | - |
| 388 | << json.constData() | - |
| 389 | << ")"; | - |
| 390 | return dbg.space(); executed: return dbg.space();Execution Count:2 | 2 |
| 391 | } | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | | - |
| | |