summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonobject.h
Commit message (Collapse)AuthorAgeFilesLines
* QJsonObject: use new comparison helper macrosTatiana Borisova2024-03-251-1/+11
| | | | | | | | | | | | | | | | | Replace public operators operator==(), operator!=() of QJsonObject to friend methods comparesEqual(). Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Add friend method comparesEqual(QJsonObject, QJsonValue) to the QJsonObject class, to support comparison between QJsonObject and QJsonValue elements, see test-case valueEquals(). Task-number: QTBUG-120300 Change-Id: Ibab0b4b39966205447e31c41e94e7e1a4e31e553 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCbor/QJson: s/QPair/std::pair/Marc Mutz2023-12-131-1/+1
| | | | | | | | | Also port qMakePair() to just braced initialization and CTAD. Pick-to: 6.7 Task-number: QTBUG-115841 Change-Id: I9eafb20ebc63bd33eb52661f4f14ad2db9fc0f00 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QVariant: make many more QtCore types nothrow-copyableThiago Macieira2022-07-301-2/+2
| | | | | | | | | | | | | | | All of those are implicitly-shared Qt data types whose copy constructors can't throw and have wide contracts (there aren't even any assertions for validity in any of them). These are all types with a QVariant implicit constructor, except for QCborValue, which is updated on this list so QJsonValue (which has a QVariant constructor) is also legitimately noexcept. To ensure we haven't made a mistake, the Private constructor checks again. Change-Id: I3859764fed084846bcb0fffd17044d8319a45e1f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtBase: eradicate QT_STRINGVIEW_LEVEL usesMarc Mutz2022-07-201-6/+0
| | | | | | | | | | | | It's not used and not useful. The macro itself has to stay, for now, because Qt5Compat uses it, too. Task-number: QTBUG-100861 Pick-to: 6.4 6.3 6.2 Change-Id: I5d0557a6c959d6facf6e47f26786a9d365339e95 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-10/+10
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QJsonValueConstRef: fix null pointer dereferencesThiago Macieira2022-03-181-1/+1
| | | | | | | | | Introduced in commit 705ea62f9e08730793adc7f6cec753c88e66ac4e, but apparently these constructors aren't used anywhere yet. Change-Id: Ic30914a4448d4bc28974fffd16dc521ab49d3be4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonValueConstRef: prepare for Qt 7Thiago Macieira2022-02-151-19/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of storing a pointer to the QJsonArray or QJsonObject (like the Qt 4 & pre-5.15 versions did), do like QCborValueConstRef and store the pointer to the QCborContainerPrivate. Unlike QCborValueRef, we must keep the is_object bit because of API behavior that assigning an Undefined to an object reference deletes it from the container. I've chosen to use size_t instead of qsizetype for this because then we don't lose any bits of the index. Therefore, the index in the case of objects is stored as pair count (like before), different from QCborValueRef which stores the actual index in the QCborContainerPrivate. It's the LSB (on little-endian architectures) so the calculation of 2 * index + 1 is the actual value stored in memory or in the register. Unfortunately, right now, both Clang and GCC don't realize this and generate unnecessary instructions. Clang: 0000000000000000 <QJsonValueConstRef::concreteType(QJsonValueConstRef)>: 0: mov %rsi,%rax 3: shr %rax 6: mov %rsi,%rcx 9: or $0x1,%rcx d: test $0x1,%sil 11: cmove %rax,%rcx [GCC code is identical, except it uses an AND instead of TEST] That OR at offset 9 is a no-op because it sets a bit that is already set in those conditions. At least they don't do unnecessary shifts. Change-Id: I89446ea06b5742efb194fffd16bb7aadb6a9b341 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJson{Array,Object}: rewrite & simplify some iterator functionsThiago Macieira2022-02-151-6/+4
| | | | | | | | | Instead of manipulating indices in multiple functions, make some call the others. This reduces the number of places porting must happen at, if we wanted to. Change-Id: I89446ea06b5742efb194fffd16bb78d24e0528b2 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJsonValueRef: optimize the assignmentThiago Macieira2022-02-151-0/+2
| | | | | | | | | | | | | | | Inline some content to avoid unnecessary round-trips through qcborvalue.cpp, qjsonarray.cpp and qjsonobject.cpp. Unlike the CBOR counterparts, JSON support has this extra functionality that assigning Undefined causes the item to be removed from the object (arrays don't have that behavior, they just become null). And unlike QCborValueRef, we detach on assignment, not on the obtention of the QJsonValueRef. This is more dangerous, so we may want to revise. Change-Id: I89446ea06b5742efb194fffd16bb775e9566ca1a Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QJsonValueConcreteRef: optimize concrete()Thiago Macieira2022-02-151-0/+1
| | | | | | | | | | | | Inline the content to avoid a round-trip through qjsonarray.cpp and qjsonobject.cpp. This change revealed an inadviseable unit test check that dereferences the end() iterator to get its type. I haven't changed it, but have marked with ###. I also fixed a likely copy&paste mistake in that test. Change-Id: I89446ea06b5742efb194fffd16bb774f3bfbe5f5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonObject: use QJsonValueConstRefThiago Macieira2022-02-151-9/+10
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b608f32f8eb4b4 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Introduce Q{Json,Cbor}ValueConstRefThiago Macieira2022-02-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I screwed up when I wrote QCborValueRef by not having the ConstRef type. The code worked, but it wasn't const-correct, allowing you to write: const QCborArray &arr = something(); *arr.begin() = QCborArray(); This mistake was brought over to QJsonValue in Qt 6.0, so it has to be fixed for QJsonValue too. The actual fixes are in the next couple of commits. This change is believed to be binary-compatible: the Q{Json,Cbor}ValueRef classes continue to have the exact same size, except that they're now empty and have a new base class. They weren't trivial before this commit doesn't change that. [ChangeLog][Potentially Source-Incompatible Changes] The iterator classes for Qt's JSON and CBOR containers (array and map/object) had a const correctness issue which allowed a const_iterator to mutate the container being iterated on, even if that container was itself const. Qt 6.4 has a fix for this, but will cause compilation issues where QCborValueRef and QJsonValueRef were used where the correctness could be violated. To keep code compiling with both 6.3 and 6.4, either change to non-const iteration or replace the QxxxValueRef with a const QxxxValue reference. This change is binary-compatible. Change-Id: I5e52dc5b093c43a3b678fffd16b6063333765ae0 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonObject: Fix operator<=()Ulf Hermann2021-02-181-1/+1
| | | | | | | | | | We had a copy-paste error there. Pick-to: 6.0 6.1 Change-Id: Ib1448197ac4f4641c6559f133f41dcf326f210f1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean up qcontainerfwd.hLars Knoll2020-11-031-4/+0
| | | | | | | | | | | | Add missing declaration of QVariantList and friends. Replace class with typename for template parameters. Remove some left-over forward declarations in other headers. Change-Id: I31d443019d48b619e02834395dafa40182cac7b9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use qsizetype for size in QJsonArray and QJsonObjectSona Kurazyan2020-08-181-28/+28
| | | | | Change-Id: I126b7e817f076486910777bb4e3354487ad670cd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Improve the iterators of QJsonArray and QJsonObjectSona Kurazyan2020-07-261-79/+97
| | | | | | | | | Remove the fake QJsonValuePtr and QJsonValueRefPtr required for operator()-> of QJsonArray and QJsonObject iterators. Task-number: QTBUG-85700 Change-Id: I622a5a426edb13b32f9d00a02c3c148320fbccba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean-up some Qt 5 leftovers from JSON serialization classesSona Kurazyan2020-07-221-9/+3
| | | | | Change-Id: I2ddf6901d627677395b39bec34c2c47d27e88d0b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Sweep Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6 -> Q_DECLARE_SHAREDMarc Mutz2020-05-191-1/+1
| | | | | | | | | | | | This is Qt 6, so Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6 is the same as Q_DECLARE_SHARED. Let's hope we'll collectively get better at detecting missing Q_DECLARE_SHARED so we won't need a Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT7 in the future. Change-Id: I3da9faff4c66b64a3b257309012a2a10a6c6d027 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change qHash() to work with size_t instead of uintLars Knoll2020-04-091-1/+1
| | | | | | | | | | | This is required, so that QHash and QSet can hold more than 2^32 items on 64 bit platforms. The actual hashing functions for strings are still 32bit, this will be changed in a follow-up commit. Change-Id: I4372125252486075ff3a0b45ecfa818359fe103b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix parameter of QJsonObject::const_iterator operator-(const_iterator)Friedemann Kleint2020-01-031-1/+1
| | | | | | | | | | | | It used to be "iterator", causing a qdoc warning: src/corelib/serialization/qjsonobject.cpp:1405: (qdoc) warning: clang found diagnostics parsing \fn int QJsonObject::const_iterator::operator-(const_iterator other) const error: out-of-line definition of 'operator-' does not match any declaration in 'QJsonObject::const_iterator' Add a small test. Change-Id: Id65effffa720ed1e0fb0ee6937dcc4298f3ef363 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Reimplement JSON support on top of CborUlf Hermann2019-10-211-19/+10
| | | | | | | | | | | | In turn, deprecate the QJsonDocument methods that deal with JSON binary data. You should use CBOR for data serialization these days. [ChangeLog][Deprecation Notice] The binary JSON representation is deprecated. The CBOR format should be used instead. Fixes: QTBUG-47629 Change-Id: Ic8b92ea36de87815b12307a9d8b1095f07166db8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QJsonObject::iterator a true random access iteratorLars Knoll2019-10-131-0/+22
| | | | | | | | | | Amends and fixes 7236721bf8bacc0978fc872d7e4805c7be7824f0 where the iterator category was changed from bidirectional to random access without adding all the required functions. Fixes: QTBUG-57353 Change-Id: I2c96448facb222c8b8f9ad4423cb0dbd1ed098f4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJsonObject: add QLatin1String overloads of non-const methodsMat Sutcliffe2019-07-201-1/+13
| | | | | | | | | | | | Also optimized the existing QL1S overload of non-const operator[](), and applied Extract Method refactoring to the other existing QL1S overloads. [ChangeLog][QtCore][QJsonObject] Added insert(), remove(), and take() overloads taking QLatin1String. Change-Id: I5e737cf2d7d9ffb325d6981db1e4a6a9f093657b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* JSON: add some QStringView overloadsMat Sutcliffe2019-07-201-6/+22
| | | | | | | | | [ChangeLog][QtCore][JSON] Added overloads of functions taking key strings as QStringView; in QJsonObject, QJsonValue and QJsonDocument. Change-Id: I78b40aba8200003acfae257ff06f5f15737005e7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* QJsonObject: minor refactoringMat Sutcliffe2019-07-201-0/+2
| | | | | | | | | Applied DRY principle. Change-Id: Ic3035552c6174167b4fe19fd4c825500dff16ded Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Optimize non-const overload of QJsonObject::operator[]Mat Sutcliffe2019-07-201-0/+1
| | | | | | | | | | | | | | | | Refactored parts of insert() into a new private method insertAt(), which can also be called by operator[]() to avoid a redundant key lookup. This is in preparation for overloading QJsonObject's non-const methods on QLatin1String. As a bonus, this also avoids a redundant key lookup in QJsonValueRef::operator=(). Change-Id: Ic481981d838e50bc55fb8e7844536749781899ce Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove handling of missing Q_COMPILER_INITIALIZER_LISTSAllan Sandfeld Jensen2019-05-021-4/+0
| | | | | | Change-Id: Id65b39c787235a051262544932e6717d076f1ea0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-3/+3
| | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Implement QJsonObject data stream operatorJędrzej Nowacki2018-10-031-0/+5
| | | | | Change-Id: I8528f18ad72828cd97a5ac00e1925958acf73f9f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* JSON: Add qHash functions for JSON and CBOR typesUlf Hermann2018-08-271-0/+2
| | | | | | | This way we can easily use them as keys in QHash and QSet. Change-Id: Ie744c3b5ad1176ba2ab035c7e650af483757a0c9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Create corelib/serialization and move existing file formats into itThiago Macieira2018-01-261-0/+271
This is in preparation to adding CBOR support. We don't need yet another dir for CBOR and placing it in src/corelib/json is just wrong. Change-Id: I9741f017961b410c910dfffd14ffb9d870340fa6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>