summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QByteArray: fix isUpper/isLowerGiuseppe D'Angelo2022-01-251-34/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 577d698b8e72bc0969ae7545a1a56d3a3d08bdda changed QString::isUpper / isLower behaviors to match Unicode semantics: a string is uppercase if it's identical to its own toLower/toUpper folding. These semantics come from Unicode so they're not up for debate. That commit however left QByteArray untouched. Generally speaking, we want to move away from QByteArray as "text storage" -- this has partially happened between Qt 5 and Qt 6, where QByteArray went from Latin-1 semantics to ASCII semantics. Still, QByteArray offers toUpper/toLower and isUpper/isLower and all this family of functions should be consistent in behavior. Apply the same fix that was applied to QString. [ChangeLog][Important Behavior Changes] The semantics of QByteArray::isLower() and QByteArray::isUpper() have been changed. Now lowercase (resp. uppercase) byte arrays are allowed to contain any character; a byte array is considered lowercase (resp. uppercase) if it's equal to its own toLower() (resp. toUpper()) folding. For instance, the "abc123" byte array is now considered to be lowercase. Previously, the isLower() (resp. isUpper()) functions checked whether the byte array only contained ASCII lowercase (resp. uppercase) characters, and was at least 1 character long. This had the side effect that byte array containing ASCII non-letters (e.g. numbers, symbols, etc.) were not lowercase nor uppercase. [ChangeLog][QtCore][QByteArray] QByteArray::isLower() and QByteArray::isUpper() now work correctly with empty byte arrays. The semantics of these functions have been changed. Pick-to: 6.3 6.2 Fixes: QTBUG-100107 Change-Id: Id56a42f01b2d1af5387bf0e6ccff0f824f757155 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QByteArrayMatcher users: use the new QByteArrayView overloadsMarc Mutz2022-01-211-2/+2
| | | | | | | | | | The new overloads mean that when passing QByteArrayView or QLatin1String objects, we don't expand them into .data() and .size() anymore. Pick-to: 6.3 Change-Id: I0c898e0463d0bf81ce1f7d57e10e64f23bd84587 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QByteArray: remove left-over Q_NEVER_INLINE after we removed the tablesThiago Macieira2022-01-121-4/+0
| | | | | | | | | | | | | | | | | | The comment made a reference to the case tables that used to exist in qbytearray.cpp prior to commit 9dd8e655cdd26eeaae30645b7fe013d9a696547f ("Limit QByteArray's 8-bit support to ASCII"). Now that the parameter is a function pointer, not a table, inlining is actually beneficial: we definitely don't want the compiler to emit function calls via the function pointer. At least GCC 11 was already doing constant-propagation of the parameter: While it didn't inline the function, it cloned it and propagated the constant in each of the two clones. There were 4 copies of this function: const and non-const, upper and lower. Change-Id: I0e5f6bec596a4a78bd3bfffd16c912a16602e20a Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QByteArray: avoid detach() in a no-op replace()Marc Mutz2022-01-031-2/+3
| | | | | | | | | | | | | When the the replacement has the same size as the replacee, but that size is zero, the whole operation is a no-op, and there's no need to detach(). [ChangeLog][QtCore][QByteArray] A replace(pos, n, after) call no longer detach()es when n == after.size() == 0. Pick-to: 6.3 6.2 Change-Id: I1e8d7c7fb6383f8bfea3212e49fca8a128535564 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QByteArray: fix UB (precondition violation) in replace()Marc Mutz2021-12-171-1/+3
| | | | | | | | | | | | | | | | | If after.isNull(), then we called memcpy with a nullptr, which is UB, even if the size is zero, too. memmove() has the same precondition. Fix by guarding the memcpy() call with an explicit length check. The Qt 5.15 code is sufficiently different to not attempt to pick there. Pick-to: 6.3 6.2 Change-Id: I86a2f00ede6ca8fab8d4222f84dccf375c4a2194 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QByteArray: optimize replace() a bitMarc Mutz2021-12-171-1/+1
| | | | | | | | These days, we perform the alias check unconditionally, so the remainder of the function can assume that *this and after do not overlap. So memcpy() suffices, we don't need memmove(). Pick-to: 6.3 6.2 Change-Id: Ib6966facfe643b0aaf50d902709f5fe926bed527 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QByteArray: sprinkle API with noexceptMarc Mutz2021-12-141-1/+1
| | | | | | | | | | | Mark (const) data()/begin()/end()/size()/empty() and similar as noexcept. Move some trivial definitions into the class body. Pick-to: 6.3 Change-Id: I6f3ab792264347cdc6a476dacecf065f59f16ff9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* corelib: Fix typos in documentationJonas Kvinge2021-10-121-4/+4
| | | | | | Pick-to: 5.15 6.2 Change-Id: I64d63af708bc6ddaabd12450eb3089e5077f849e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add isValidUtf8() methods to QUtf8StringView and QByteArray{,View}Ievgenii Meshcheriakov2021-09-221-0/+18
| | | | | | | | | | | | | | | The new methods return true if the string contains valid UTF-8 encoded data, or false otherwise. [ChangeLog][QtCore][QByteArray] Added isValidUtf8() method. [ChangeLog][QtCore][QByteArrayView] Added isValidUtf8() method. [ChangeLog][QtCore][QUtf8StringView] Added isValidUtf8() method. Task-number: QTBUG-92021 Change-Id: I5d0cb613265d98b1f189c5f5cc09c1f7db302272 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Teach QByteArrayView how to parse numbersEdward Welbourne2021-08-301-2/+50
| | | | | | | | | | | | Now that we don't need '\0'-termination on the data, this is possible. Moved QByteArray's tests to tst_QByteArrayApiSymmetry and added some more test-cases. [ChangeLog][QtCore][QByteArrayView] Added numeric parsing methods. Change-Id: Ic0df91ecfe5dbf6f008d344dd0464d7927f32273 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Rework QLocalePrivate::bytearrayToU?LongLong()Edward Welbourne2021-08-301-12/+12
| | | | | | | | | | | | Change it to take a QByteArrayView instead of a plain char *; all its callers do know the size and propagating it enables the implementation to call strntou?ll() rather than strtou?ll(), thereby escaping the need for '\0'-termination. Fixes: QTBUG-74286 Change-Id: Ie9394786e9fcf25c1d1be2421805f47c018d13bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QBA(V)/QS(V)::lastIndexOf: fix the search of 1-char needlesGiuseppe D'Angelo2021-08-261-0/+2
| | | | | | | | | | | | | | | | | | | | When a needle has length 1 (because it's a QChar/char16_t, or because it's a string-like of length 1) then an ad-hoc search algorithm is used. This algorithm had a off-by-one, by not allowing to match at the last position of a haystack (in case `from` was `haystack.size()`). That is inconsistent with the general search of substring needles (and what QByteArray does). Fix that case and amend wrong tests. This in turn unveiled the fact that the algorithm was unable to cope with 0-length haystacks (whops), so fix that as well. Drive-by, add a similar fix for QByteArray. Amends 6cee204d56205e250b0675c9c6d4dd8a2367f3c4. Pick-to: 6.2 Change-Id: I6b3effc4ecd74bcbcd33dd2e550da2df7bf05ae3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QS(V)/QBA(V)/QL1S::lastIndexOf: fix the offset calculationsGiuseppe D'Angelo2021-08-191-4/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to fix 0-length matches at the end of a QString, be83ff65c424cff1036e7da19d6175826d9f7ed9 actually introduced a regression due to how lastIndexOf interprets its `from` parameter. The "established" (=legacy) interpretation of a negative `from` is that it is supposed to indicate that we want the last match at offset `from + size()`. With the default from of -1, that means we want a match starting at most at position `size() - 1` inclusive, i.e. *at* the last position in the string. The aforementioned commit changed that, by allowing a match at position `size()` instead, and this behavioral change broke code. The problem the commit tried to fix was that empty matches *are* allowed to happen at position size(): the last match of regexp // inside the string "test" is indeed at position 4 (the regexp matches 5 times). Changing the meaning of negative from to include that last position (in general: to include position `from+size()+1` as the last valid matching position, in case of a negative `from`) has unfortunately broken client code. Therefore, we need to revert it. This patch does that, adapting the tests as necessary (drive-by: a broken #undef is removed). Reverting the patch however is not sufficient. What we are facing here is an historical API mistake that forces the default `from` (-1) to *skip* the truly last possible match; the mistake is that thre is simply no way to pass a negative `from` and obtain that match. This means that the revert will now cause code like this: str.lastIndexOf(QRE("")); // `from` defaulted to -1 NOT to return str.size(), which is counter-intuitive and wrong. Other APIs expose this inconsistency: for instance, using QRegularExpressionIterator would actually yield a last match at position str.size(). Similarly, using QString::count would return `str.size()+1`. Note that, in general, it's still possible for clients to call str.lastIndexOf(~~~, str.size()) to get the "truly last" match. This patch also tries to fix this case ("have our cake and eat it"). First and foremost, a couple of bugs in QByteArray and QString code are fixed (when dealing with 0-length needles). Second, a lastIndexOf overload is added. One overload is the "legacy" one, that will honor the pre-existing semantics of negative `from`. The new overload does NOT take a `from` parameter at all, and will actually match from the truly end (by simply calling `lastIndexOf(~~~, size())` internally). These overloads are offered for all the existing lastIndexOf() overloads, not only the ones taking QRE. This means that code simply using `lastIndexOf` without any `from` parameter get the "correct" behavior for 0-length matches, and code that specifies one gets the legacy behavior. Matches of length > 0 are not affected anyways, as they can't match at position size(). [ChangeLog][Important Behavior Changes] A regression in the behavior of the lastIndexOf() function on text-related containers and views (QString, QStringView, QByteArray, QByteArrayView, QLatin1String) has been fixed, and the behavior made consistent and more in line with user expectations. When lastIndexOf() is invoked with a negative `from` position, the last match has now to start at the last character in the container/view (before, it was at the position *past* the last character). This makes a difference when using lastIndexOf() with a needle that has 0 length (for instance an empty string, a regular expression that can match 0 characters, and so on); any other case is unaffected. To retrieve the "truly last" match, one can pass a positive `from` offset to lastIndexOf() (basically, pass `size()` as the `from` parameter). To make calls such as `text.lastIndexOf(~~~);`, that do not pass any `from` parameter, behave properly, a new lastIndexOf() overload has been added to all the text containers/views. This overload does not take a `from` parameter at all, and will search starting from one character past the end of the text, therefore returning a correct result when used with needles that may yield 0-length matches. Client code may need to be recompiled in order to use this new overload. Conversely, client code that needs to skip the "truly last" match now needs to pass -1 as the `from` parameter instead of relying on the default. Change-Id: I5e92bdcf1a57c2c3cca97b6adccf0883d00a92e5 Fixes: QTBUG-94215 Pick-to: 6.2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QByteArray: Disentangle number(double) from QLocaleMårten Nordheim2021-08-171-7/+2
| | | | | | | | | | | | | | Previously number(double) would go through QLocale which takes a lot of factors into consideration (which we don't need in this case) and outputs a QString in the end, which we then have to convert back to QByteArray. Avoid all that extra work and format it directly into a QByteArray. The other number() functions do not use QLocale, so are left alone for now. Task-number: QTBUG-88484 Change-Id: I4c2eaf101a55ba16e858f95017fb171589a0184e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add QByteArrayView::trimmed()Edward Welbourne2021-08-111-0/+7
| | | | | | | | | | | | Unlike simplified(), it just moves the end-points, without needing to modify contents, so it makes sense (as for QStringView and QLatin1String) to provide it. Moved QByteArray's trimmed() tests to tst_QByteArrayApiSymmetry so that QBAV can now share them. [ChangeLog][QtCore][QByteArrayView] Added trimmed(). Change-Id: Ifd7a752adb5f3d3e2ad0aa8220efa7e7d2d39baa Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Consolidate documentation of floating-point formatting codeEdward Welbourne2021-08-031-74/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the documentation of the format and precision parameters to QLocale::toString(double, char, int), reference it from various QString methods (instead of repeating there and referencing one of those from QLocale). Add brief first lines for various documentation comments. Mention the special handling of negative precision in the moved documentation. Mention QLocale::FloatingPointShortest, add its type to \sa lines of methods it affects. Change a comment on some code implementing its special treatment to make clear that it does apply to 'e' and 'f' formats, not only to 'g', even though it has no overt special handling in that code; and update docs to report the undocumented behavior the comment previously described. Document how infinity and NaN are represented. Be somewhat more consistent about single-quoting the format names where referred to and applying \c to character constants. Make clear what things are different between different methods using these parameters. Reference QString::number() from QByteArray's relevant methods, since they share its quirks. In the process, rename the format and precision parameters of relevant functions so they're consistently named, replacing a mixture of abbreviated forms. Pick-to: 6.2 Change-Id: I077521b30346000e4b4f6968a8e750e934f72937 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QByteArray: don't coerce negative to unsigned for any baseEdward Welbourne2021-08-021-2/+3
| | | | | | | | | | | | | | | | This follows up on commit 98666c8afc80cccb80ca4426b97ec52916c6e610, which did the same for QString. If someone wants to get formatting suitable to an unsigned value, they can cast the value to that unsigned type and the correct overload shall pick it up. [ChangeLog][Important Behavior Changes] QByteArray's formatting of negative whole numbers to bases other than ten now, like QString's (since Qt 6.0), formats the absolute value and prepends a minus sign. Task-number: QTBUG-53706 Pick-to: 6.2 Change-Id: I91fee23d25ac0d5d5bcfcbeccbac1386627c004a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QByteArray::number/setNum(double): Reverse dependencyMårten Nordheim2021-08-021-30/+27
| | | | | | | | | | | | | | | | Currently number(double) creates a QByteArray-instance and calls setNum(double). setNum(double) creates a QByteArray-instance and copy-assigns it to itself. By making setNum(double) call number(double) we can cut one creation from numbers(double)'s path, and making setNum no worse than it was. The other pairs of setNum/number are left alone as they don't have this issue. Change-Id: Ib611ebc78db64f74244a56cb8e384e42bc7d1758 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QByteArray: fix indexOf/lastIndexOfIvan Solovev2021-07-291-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixed two bugs in indexOf/lastIndexOf: 1. The lastIndexOf(char, qsizetype) overload was crashing with an empty QByteArray. It was unconditionally calling lastIndexOfCharHelper() which assumes that this QBA is not empty. An explicit check for the empty case is added. 2. The indexOf(QByteArray, qsizetype) overload was behaving incorrectly while searching for an empty QByteArray. In this case it unconditionally returned its second parameter (from). However, from can be negative, or even exceed the size of this QByteArray. This patch handles this cases properly. As a drive-by: this patch adjusts the QByteArray::indexOf(char, qsizetype) and QByteArray::lastIndexOf(char, qsizetype) overloads to match with the QByteArrayView implementation. This is done to have similar code paths in both cases and avoid tricky bugs in future. Ideally we had to adjust the QByteArrayView implementation, but it's fully inline, so can't be changed without breaking BC. Task-number: QTBUG-91736 Pick-to: 6.2 6.1 Change-Id: Iaef2fdc5b99cce6aa342cca2d17544a1ad7ca677 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Resurrect data moves in QListAndrei Golubev2021-04-271-14/+5
| | | | | | | | | | | | | | | | | Use the data moves to readjust the free space in the QList, which ultimately fixes the out-of-memory issues caused by cases like: forever { list.prepend(list.back()); list.removeLast(); } Task-number: QTBUG-91801 Task-number: QTBUG-91360 Task-number: QTBUG-93019 Change-Id: Iacff69cbf36b8b5b176bb2663df635ec972c875c Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit a0253f5f0249024580050e4ec22d50cb139ef8d9)
* Add q_points_into_range to container utilitiesAndrei Golubev2021-04-271-10/+4
| | | | | | | | | | We already used it in QString and QBA. And implicitly in QADP (see parent commit). Might as well move to a common location and reuse Change-Id: I694f0f1dbd109f17c134f64b3f3dc28d19556c88 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 10b46e7f0faecc42a94cc2e25ad3edd08ae28083) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix qdoc warning, \function is not a commandVolker Hilsheimer2021-04-131-7/+9
| | | | | | | | | | | | | Document the size parameter while at it, and rephrase a bit. This introduces a new qdoc warning since QtLiteral is a new namespace without any documentation, but that's for a separate commit. Change-Id: I849d5cdde8b64dbbe7e6a526214d422930091cd4 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Nico Vertriest <nico.vertriest@qt.io>
* Add literal operators for QString and QByteArrayAndrei Golubev2021-03-301-0/+21
| | | | | | | | | | | | [ChangeLog][QtCore][QString] Added literal operator u"..."_qs that converts a char16_t string literal to QString [ChangeLog][QtCore][QByteArray] Added literal operator "..."_qba that converts char string literal to QByteArray Change-Id: I4aa59b28cc17bff346b378eb70008fb8185d21ac Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use Core library for qmake instead of the Bootstrap libraryAlexey Edelev2021-02-251-1/+1
| | | | | | | | | | | | | | | | | | | Move the qmake-specific logic of the QLibraryInfo class to qmake internals. 'qconfig.cpp.in' now stores information about the library info entries to keep them consistent between qmake and the Core library. qmake requires specific features enabled in the Core library, so building qmake will be skipped if the features are not enabled. All flags directly related to the qmake have been removed from Core lib. Remove all bootstrap related sections from qmake CMakeLists.txt Task-number: QTBUG-89369 Change-Id: I26de157d3bfd4a5526699296e9d46e1c180b89ae Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Fix qdoc warning from incorrectly named method parameterVolker Hilsheimer2020-12-081-2/+2
| | | | | | | | | | | Amends 2eb7d6073d5132a8bf269f5c6fc9f89fde446ab5. Pick-to: 6.0 Task-number: QTBUG-87962 Change-Id: I55c9e8cf7db9e1e1644a76f29a9dc61b161ae551 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QByteArray: update documentationIvan Solovev2020-12-051-69/+147
| | | | | | | | | | | | | The QByteArray documentation is extended to align with QList and QString regarding common wording and ideas: - Extend general class description - Revise description of several methods - Wrap descriptions at 80 characters Pick-to: 6.0 Task-number: QTBUG-87962 Change-Id: Ie9e8ef47a85d0867c2fa63889a60cafbe76ee47a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString/QByteArray: add missing Q_CHECK_PTRThiago Macieira2020-12-041-0/+7
| | | | | | | | | | | | | | So these two classes throw when trying to allocate silly sizes or in OOM conditions. We probably want to move these Q_CHECK_POINTER into QTypedArrayData but I didn't want to do that in this commit. Task-number: QTBUG-88256 Task-number: QTBUG-88253 Change-Id: Ifc61bb80b9bf48a386abfffd1648176111770174 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QString/QByteArray: add erase/erase_ifGiuseppe D'Angelo2020-12-011-0/+31
| | | | | | | | | | | | | [ChangeLog][QtCore][QString] Added erase() and erase_if() for consistent container erasure. [ChangeLog][QtCore][QByteArray] Added erase() and erase_if() for consistent container erasure. Change-Id: I23e8565d39044c1f1d756500589c1f2b65e1a88f Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString/QByteArray: add erase() for iteratorsGiuseppe D'Angelo2020-11-261-0/+15
| | | | | | | | | | | | | Otherwise they're not usable with iterator-based algorithms that e.g. remove, partition and the like. [ChangeLog][QtCore][QString] Added erase(). [ChangeLog][QtCore][QByteArray] Added erase(). Change-Id: I78829b1a5365dd53b6b6423ceedbc52edeafbc63 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Doc: Remove wrong \obsolete doc commentsKarsten Heimrich2020-11-191-4/+7
| | | | | Change-Id: I541f12fab128493235716fb73d65f4ab0a62bb82 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix signature of QArrayDataOps::erase()Lars Knoll2020-11-171-1/+3
| | | | | | | | | | | | Bring it in line with the other methods that also take a pointer and a size. Also use truncate() in removeAll() as that's more efficient for the use case. Change-Id: Ib1073b7c048ceb96fb6391b308ef8feb77896866 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean realloc() related bits in QString/QBA and Q*ArrayOpsAndrei Golubev2020-11-121-5/+4
| | | | | | | | | | | | | | | Fixed misleading naming of "slowReallocatePath". It's no longer "slow", it's downright dangerous now to reallocate under certain conditions Added several asserts which should've been there already as our code would run into a UB/crash anyhow - let's at least get extra checks that are closer to the trouble causing places Bring back the (slightly modified) code-cleaning changes from 504972f838761f79a170c22225add496e7e5af6a Change-Id: Ie1358aebc619062d3991a78049e366dc0e8c267e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add QByteArray::insert(qsizetype, const QByteArray &)Mårten Nordheim2020-11-111-0/+18
| | | | | | | | | | | | | | | | For consistency with append and prepend we should have an overload for insert() as well. This also enables insert() to be used with QStringBuilder, i.e. qba.insert(2, qba2 + "abc"). Because simply adding a const QByteArray & overload causes ambiguity with QByteArrayView we also add a const char * overload. Add some extra test-cases. Two for QByteArrayView since it's not directly tested anymore. One for inserting self directly. Change-Id: Ieb43a6a7d1afbb498bc89c690908d7f0faa94687 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Revert "Refine {QString, QBA}::reallocData() logic"Volker Hilsheimer2020-11-081-4/+5
| | | | | | | | | | This reverts commit 504972f838761f79a170c22225add496e7e5af6a. Introduced realloc failures in qdoc. Task-number: QTBUG-88258 Change-Id: I953e8d3933085022c75068af357ec9a44ab7e984 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Refine {QString, QBA}::reallocData() logicAndrei Golubev2020-11-061-5/+4
| | | | | | | | | | | | Fixed misleading naming of "slowReallocatePath". It's no longer "slow", it's downright dangerous now to reallocate under certain conditions While at it, added extra assert to QArrayData::reallocateUnaligned() and cleaned up that function a bit Change-Id: I05921fb5058eb563997e66107566c87fb4ea5599 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Rename AllocationPosition enum and its membersLars Knoll2020-11-041-3/+3
| | | | | | | Use GrowsAt* and GrowthPosition as that is clearer. Change-Id: I3c173797dec3620f508156efc0c51b4d2cd3e142 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move insert() operation into QArrayDataOpsLars Knoll2020-11-041-51/+36
| | | | | | | | | This allows us to unify and simplify the code base between QList, QString and QByteArray. Change-Id: Idc8f360d78f508a68f38eb3ef0ed6e5d37f90574 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Clean up out allocation handlingLars Knoll2020-11-041-10/+11
| | | | | | | | | | Get rid of the allocation options inside the flags field of QArrayData, they are really a completely separate thing. Change-Id: I823750ab9e4ca85642a0bd0e471ee79c9cde43fb Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cleanup QArrayDataOps::reallocate() and relatedLars Knoll2020-11-041-3/+3
| | | | | | | | | | Don't use QArrayData::GrowsForward/Backward anymore and replace it with a simple 'bool grow'. Change-Id: Ifddfef3ae860b11dda4c40854c71ef2aeb29df34 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Don't move data in QArrayDataOps::reallocate()Lars Knoll2020-11-041-3/+3
| | | | | | | | | reallocate() should only ever call realloc(), and only be used to create more space at the end of the data. Change-Id: I2ac4dbc90d2afaa571bb620108d7984356712cb2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Avoid expensive iterator calculations in append()Lars Knoll2020-11-041-45/+55
| | | | | | | | | | | | | Avoid moving data inside the array to create free space at one end. This is a performance bottleneck, as it required quite a lot of calculations for every insert. Rather reallocate and grow in this case, so we only need to do expensive work when we reallocate the array. Change-Id: Ifc955fbcf9967c3b66aa2600e0627aac15f0c917 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* QArrayDataPointer: redesign (and simplify) growth policyAndrei Golubev2020-11-041-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | It looks like we can drastically simplify the way QADP grows without sacrificing much: 1. append-only use cases should have the same performance as before 2. prepend-only use cases should (with the help of other commits) get additional performance speedup 3. mid-insertion is harder to reason about, but it is either unchanged or benefits a bit as there's some free space at both ends now 4. mixed prepend/append cases are weird and would keep excess free space around but this is less critical and overall less used AFAIK Now, QList would actually start to feel like a double-ended container instead of "it's QVector but with faster prepend". This commit should help close the performance gap between 6.0 and 5.15 as well As a drawback, we will most likely have more space allocated in mixed and mid-insert cases. This needs to be checked Task-number: QTBUG-86583 Change-Id: I7c6ede896144920fe01862b9fe789c8fdfc11f80 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Fix various documentation issues for Qt CoreTopi Reinio2020-10-311-1/+1
| | | | | | | Task-number: QTBUG-86295 Change-Id: I3bf7d4b1533d4fc81114d353b19beaf4ea9b93b2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Make QByteArray comparison operators hidden friendsVolker Hilsheimer2020-10-291-58/+20
| | | | | | | | | | Also for QByteArray::FromBase64Result, to reduce ADL noise. Add explicit overload for comparison with nullptr to avoid ambiguous overload errors with '0' comparisons. Change-Id: I7ff9dbc90581707856c10cf7fb835175dfcdb55e Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Doc: Scrub QByteArray/QByteArrayView documentationKarsten Heimrich2020-10-291-16/+16
| | | | | | Fixes: QTBUG-86555 Change-Id: I3221e0de10e692ca767eeb69daa82da55b93e395 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QByteArray: make (ap|pre)pend(const QByteArray &) consider reservedMårten Nordheim2020-10-281-1/+7
| | | | | | | | | | Append was previously optimized for lhs being empty but it should've also taken into account if space had been reserved. Apply the same optimization to prepend while we're at it. Change-Id: I5e5d33a3189b9ad88d45e858a2ac412cbc294f79 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QADP capacity functions use qsizetype instead of size_tAndrei Golubev2020-10-081-2/+2
| | | | | | | | | | | | | | | Change types returned and accepted by capacity-related QArrayDataPointer functions to qsizetype: 1) QArrayData (underlying d-ptr) works with qsizetype 2) QArrayDataPointer::size is of type qsizetype 3) All higher level classes that use QADP (e.g. containers) cast capacity to qsizetype in their methods Additionally, fixed newly appeared warnings through qtbase Change-Id: I899408decfbf2ce9d527be7e8b7f6382875148fc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix ubsan errorsAllan Sandfeld Jensen2020-09-301-1/+1
| | | | | | | | Nullptr memcpy, memmove and 36 bit shift of integer. Change-Id: Ib79c8a98a710d021fc93b6aaec6c0ba9bde5f91e Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix some qdoc warnings from QByteArrayVolker Hilsheimer2020-09-231-17/+0
| | | | | | | | A snippet bug, and removed overloads. Change-Id: I82aee3627ba1a4e75e392b28d8ec72d470c395db Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Fix some MSVC conversion warningsFriedemann Kleint2020-09-221-1/+1
| | | | | Change-Id: Ib2c1fdb7b84f89201136438362ab5962126ec929 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>