summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qcborvalue_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Silence Clazy's warning in QCborContainerPrivate::insertAt()Vladimir Belyavsky2024-04-211-1/+1
| | | | | | | | | | Use more suitable QList::insert() overload and silence Clazy's "mixing iterators" warning. The warning is non-sense for this particular place, but it won't harm to avoid C-style cast and iterators arithmetics there. Change-Id: Ibfc8c8003473de3b7d9b67965e25a4cdb6a9f043 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CBOR: implement UTF16-to-UTF8 comparison without memory allocThiago Macieira2024-04-171-1/+1
| | | | | | | | | | | | This is similar to the UTF16-to-UTF16 comparison code added in commit d4c7da9a07dc1434692fe08a61ba22c794574c4f, but instead of converting to UTF-32, we convert to UTF-8 so we only need to convert one string. This change allows us to mark the entire recursive comparison sequence as noexcept. Change-Id: I5f663c2f9f4149af84fefffd17c07971d8b368cc Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* CBOR: implement faster comparison for equality in stringsThiago Macieira2024-04-121-2/+4
| | | | | | | | If we don't need to sort, then we can use QtPrivate::equalStrings() to get a few cycles of performance per string comparison. Change-Id: I5f663c2f9f4149af84fefffd17c03d9b52ca696e Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCborValue: avoid a double isAscii checkGiuseppe D'Angelo2024-04-111-3/+3
| | | | | | | | | | The QCborValue(QL1S) constructor checks if the parameter is ASCII. If it's not, it converts it to a QString and stores as such. However, the QString is checked *again* for being ASCII. We know it isn't -- skip this recheck. Change-Id: I7a4776759b2b14aab955cffebde6e3b64f8ed1d1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CBOR: add QtCbor::Comparison and pass it to the comparing functionsThiago Macieira2024-04-081-6/+13
| | | | | | | No-op for now. The actual optimization is in the next commit. Change-Id: I5f663c2f9f4149af84fefffd17c03cdd40c5fd4a Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Implement QCborContainerPrivate::compact()Ivan Solovev2024-02-051-6/+12
| | | | | | | | | | | | | | ... and use it in QCborContainerPrivate::replaceAt_complex() to avoid unconstrained memory growth in certain scenarios. Remove the `reserved` parameter, because it was referring to the elements array, not to the byte data, so it cannot really be used in the implementation. Fixes: QTBUG-109073 Pick-to: 6.7 Change-Id: I2e8fe7e4a4bf7a0ce06c87ca657f2bc01bae0341 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtBase: eradicate QT_STRINGVIEW_LEVEL usesMarc Mutz2022-07-201-2/+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>
* Allow brace initialization for some of QLatin1StringView constructorsSona Kurazyan2022-04-011-1/+1
| | | | | | | | | | | | | | | Removed "explicit" keyword from constructors taking (const char *, qsizetype) and (const char *, const char *). Switched to using brace initialization for creating QLatin1StringView in QtCore. [ChangeLog][QtCore][QLatin1StringView] The (const char *, qsizetype) and (const char *, const char *) constructors are no longer explicit. Change-Id: I4f6760692e4df60fe4231e86a25f6ea03cd1bf82 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-3/+3
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QCborValueRef: merge the operator[] into a templateThiago Macieira2022-02-151-0/+1
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6e94ad9d3f39b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: merge the const operator[] into a templateThiago Macieira2022-02-151-2/+11
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6ec4b7d841955 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: merge the non-const operator[] into a templateThiago Macieira2022-02-151-0/+1
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6e7b32b3e2835 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborMap: merge the operator[] methods into a templateThiago Macieira2022-02-151-0/+24
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6e7a123338178 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborMap: merge the constFind methods into a templateThiago Macieira2022-02-151-0/+21
| | | | | Change-Id: I5e52dc5b093c43a3b678fffd16b6e558c4e1f089 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QJsonObject: use the UTF-8 string comparator in sortingThiago Macieira2022-01-121-0/+1
| | | | | | | | | | No change, the two functions are identical for case-sensitive comparison. But this allows us to remove the comment that explained why we were abusing the Latin1 comparator. Change-Id: I0e5f6bec596a4a78bd3bfffd16c98bbcac6c9dc9 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: avoid allocating result if data is insufficientThiago Macieira2020-12-061-2/+8
| | | | | | | | | | | Similar to the previous commit which applied to QCborStreamReader, don't allocate too much data before checking that the stream actually has that much. Pick-to: 5.15 6.0 Fixes: QTBUG-88256 Change-Id: I7b9b97ae9b32412abdc6fffd16454b7568a063ba Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Convert a couple of APIs to use viewsLars Knoll2020-10-061-2/+2
| | | | | | | | | | | Try to get rid of APIs that use raw 'const {char, QChar} *, length' pairs. Instead, use QByteArrayView or QStringView. As QStringConverter is a new class, simply change the API to what we'd like to have. Also adjust hidden API in QStringBuilder and friends. Change-Id: I897d47f63a7b965f5574a1e51da64147f9e981f6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use QList instead of QVector in corelibJarek Kobus2020-06-251-1/+1
| | | | | | | | | | Applied to headers only. Source file to be changed separately. Omitted statemachine for now to avoid conflicts. Omitted qmetatype.h for now - to be handled later. Task-number: QTBUG-84469 Change-Id: I317376037a62467c313467d92955ad0b7473aa97 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-3/+3
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Move the UTF conversion methods to qstringconverterLars Knoll2020-05-141-1/+1
| | | | | | | | | | | | | | Separate them from the qutfcodec, so that the codec can later on be moved out of Qt Core. Fix the QUtf methods to take qsizetype instead of int for length arguments. This also makes it possible to not build QTextCodec into the bootstrap lib anymore. Change-Id: I0b4f83139d61b19c651520a2f3a5012aa7e85cb8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2020-04-081-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: examples/opengl/doc/src/cube.qdoc src/corelib/global/qlibraryinfo.cpp src/corelib/text/qbytearray_p.h src/corelib/text/qlocale_data_p.h src/corelib/time/qhijricalendar_data_p.h src/corelib/time/qjalalicalendar_data_p.h src/corelib/time/qromancalendar_data_p.h src/network/ssl/qsslcertificate.h src/widgets/doc/src/graphicsview.qdoc src/widgets/widgets/qcombobox.cpp src/widgets/widgets/qcombobox.h tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro tests/manual/diaglib/debugproxystyle.cpp tests/manual/diaglib/qwidgetdump.cpp tests/manual/diaglib/qwindowdump.cpp tests/manual/diaglib/textdump.cpp util/locale_database/cldr2qlocalexml.py util/locale_database/qlocalexml.py util/locale_database/qlocalexml2cpp.py Resolution of util/locale_database/ are based on: https://codereview.qt-project.org/c/qt/qtbase/+/294250 and src/corelib/{text,time}/*_data_p.h were then regenerated by running those scripts. Updated CMakeLists.txt in each of tests/auto/corelib/serialization/qcborstreamreader/ tests/auto/corelib/serialization/qcborvalue/ tests/auto/gui/kernel/ and generated new ones in each of tests/auto/gui/kernel/qaddpostroutine/ tests/auto/gui/kernel/qhighdpiscaling/ tests/libfuzzer/corelib/text/qregularexpression/optimize/ tests/libfuzzer/gui/painting/qcolorspace/fromiccprofile/ tests/libfuzzer/gui/text/qtextdocument/sethtml/ tests/libfuzzer/gui/text/qtextdocument/setmarkdown/ tests/libfuzzer/gui/text/qtextlayout/beginlayout/ by running util/cmake/pro2cmake.py on their changed .pro files. Changed target name in tests/auto/gui/kernel/qaction/qaction.pro tests/auto/gui/kernel/qaction/qactiongroup.pro tests/auto/gui/kernel/qshortcut/qshortcut.pro to ensure unique target names for CMake Changed tst_QComboBox::currentIndex to not test the currentIndexChanged(QString), as that one does not exist in Qt 6 anymore. Change-Id: I9a85705484855ae1dc874a81f49d27a50b0dcff7
| * QCborValue: apply a simple optimization to avoid unnecessary allocationsThiago Macieira2020-03-251-1/+0
| | | | | | | | | | | | | | | | | | If the map or array is known to be empty, we don't need to allocate a QCborContainerPrivate. Change-Id: Ief61acdfbe4d4b5ba1f0fffd15fe212b6a6e77c3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
| * QCborValue::fromCbor: Apply a recursion limit to decodingThiago Macieira2020-03-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A simple 16k file can produce deep enough recursion in Qt to cause stack overflow. So prevent that. I tested 4096 recursions just fine on my Linux system (8 MB stack), but decided 1024 was sufficient, as this code will also be run on embedded systems that could have smaller stacks. [ChangeLog][QtCore][QCborValue] fromCbor() now limits decoding to at most 1024 nested maps, arrays, and tags to prevent stack overflows. This should be sufficient for most uses of CBOR. An API to limit further or to relax the limit will be provided in 5.15. Meanwhile, if decoding more is required, QCborStreamReader can be used (note that each level of map and array allocates memory). Change-Id: Iaa63461109844e978376fffd15fa0fbefbf607a2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
| * QCborValue: create a wrapper to set the QCborStreamReader error stateThiago Macieira2020-03-251-0/+1
| | | | | | | | | | | | | | | | The next commit will need to do so from outside QCborContainerPrivate, where QCborStreamReader::d can't be accessed (private). Change-Id: Iaa63461109844e978376fffd15fa0f6f04081bf2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Merge remote-tracking branch 'origin/5.15' into devSimon Hausmann2020-03-161-1/+2
|\| | | | | | | | | | | | | Conflicts: src/corelib/kernel/qmetatype.cpp Change-Id: I88eb0d3e9c9a38abf7241a51e370c655ae74e38a
| * Port from deprecated std::is_pod to is_trivial + is_standard_layoutMarc Mutz2020-03-061-1/+2
| | | | | | | | | | | | | | | | The std::is_pod trait is deprecated in C++20; is_trivial and is_standard_layout exist since C++11. Change-Id: I4b901d8edf1a55001764445aee9c338d3dc23b21 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2019-12-111-2/+1
|\| | | | | | | | | | | | | Conflicts: tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp Change-Id: I6b82507bf9a80a374c40393e72f4843f1557de89
| * QCborValue: fix replacing of elements with byte data with ones withoutThiago Macieira2019-12-051-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | We forgot to reset the flags when replacing the element, so we ended up with an integer with HasByteData after: testMap[0] = QStringLiteral("value"); testMap[0] = 42; Fixes: QTBUG-80342 Change-Id: Ia2aa807ffa8a4c798425fffd15dabfa066ea84b0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Add functions for facilitating adding UTF-8 and US-ASCII stringsThiago Macieira2019-11-191-0/+9
| | | | | | | | | | Change-Id: Ief874765cd7b43798de3fffd15a9c0b4dc82a64e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Make QList an alias to QVectorLars Knoll2019-10-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This is almost 100% source compatible with Qt 5. Exceptions are * Stability of references for large or non movable types * taking a PMF for types that are now overloaded with r-value references in QVector * The missing prepend optimization in QVector (that is still planned to come for Qt 6) Change-Id: I96d44553304dd623def9c70d6fea8fa2fb0373b0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Replace Q_ALIGNOF usage in qtbase with C++11 alignof keywordVolker Hilsheimer2019-10-291-3/+3
|/ | | | | | | | | | | | | | | | The macro is not documented, so not part of the public Qt API. It is made obsolete by the alignof keyword in C++11. Remove the usage of the macro across qtbase, in particular the workarounds for compilers that didn't support alignof, and that will not be supported in Qt 6. The macro definition is left in place, no need to break existing code. Task-number: QTBUG-76414 Change-Id: I1cfedcd4dd748128696cdfb546d97aae4f98c3da Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Cbor: Add overloads for QStringViewUlf Hermann2019-08-221-20/+36
| | | | | Change-Id: I8d22d0741c4d3852b438b12099f81ed87244871d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change QCborArray to pad with invalid on inserting past endEdward Welbourne2018-10-081-0/+1
| | | | | | | | | Likewise have mutating operator[] insert an invalid entry at its target index, if beyond the end of the array. This makes it possible to fill an array from high index to low, for example. Change-Id: If71699c20e2623142214ce2c11c4d6e4a120c989 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValue: move the toDiagnosticNotation() function to its own fileThiago Macieira2018-07-301-0/+2
| | | | | | | | | | If we ever need to add QCborValue to the bootstrap library, it's unlikely that we'll need this part. And by splitting it, I can make the code handle more cases, that hadn't been properly handled before. Change-Id: I2f630efbbce54f14bfa9fffd154160c0ad893695 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: Silence Coverity warning about null-pointer dereferenceThiago Macieira2018-07-141-2/+2
| | | | | | | | | | | | It's a false positive, since we've checked that the item HasByteData. But it's cheap to rewrite so the warning is silenced. >>> CID 190741: Null pointer dereferences (NULL_RETURNS) >>> Dereferencing a null pointer "this->byteData(idx)". Change-Id: If48c5c2e920c433298f1fffd153f7534be42a30b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborArray & Map: implement move semanticsThiago Macieira2018-07-051-7/+12
| | | | | | | | | | | There isn't a lot of efficiency gain, since QCborValue was already refcounted. This saves two atomic operations and an out-of-line call. In the case of QCborValueRef (which includes QCborMap), because we reset the container pointer in inline code, the call to QCborValue::dispose() is also suppressed. Change-Id: Icc2c231dc2c44abdb087fffd1533eaba7a9c70fa Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* QCborArray & Map: implement efficient take() / extract()Thiago Macieira2018-07-041-2/+23
| | | | | | | | | | | | Questions: 1) should QCborMap::extract return value_type (a pair) instead of just the value? 2) should the both return the iterator to the next element too, like erase()? Change-Id: I052407b777ec43f78378fffd15302a9c14468db3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValue: store US-ASCII strings as 8-bitThiago Macieira2018-06-181-3/+8
| | | | | | | | | | | | They're easy to convert back to UTF-16, their length is the same, they occupy half the memory and they're easy to encode into CBOR (no transformation necessary). The code was copied from QJsonPrivate::Latin1String::operator=(). Change-Id: I56b444f9d6274221a3b7fffd150c52bcb6c97f37 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValue: add support for QVariant and JSON conversionsThiago Macieira2018-06-081-2/+1
| | | | | | | Plus QStringList. Change-Id: I39332e0a867442d58082fffd1508dfb9b540af23 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Long live DOM API for CBOR!Thiago Macieira2018-06-081-0/+366
This is very similar to QJsonDocument, but there's no QCborDocument. QCborValue is that. [ChangeLog][QtCore] Added QCborValue, QCborArray and QCborMap, classes that permit DOM-like access to CBOR data. The API is similar to QJsonValue, QJsonArray and QJsonObject, respectively. Change-Id: I9741f017961b410c910dfffd14ffca50dd8ef3ba Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>