summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
Commit message (Collapse)AuthorAgeFilesLines
* Fix compilation for recursive Qt containersSona Kurazyan2021-09-071-6/+6
| | | | | | | | | | | | | | | | | | | | | The operator checks cause compilation errors when trying to check for their existence for recursive containers. This happens because of trying to check for the operators on the template parameter type(s), that inherit from the container itself, which leads to compilation errors. Introduced alternative versions of the operator checks (with _container suffix), that first check if the container is recursive, i.e. any of its template parameter types inherits from the given container, and skips the operator check, if that's the case. The fix is done for all Qt container types that had the problem, except for QVarLengthArray and QContiguousCache, which don't compile with recursive parameter types for unrelated reasons. Fixes: QTBUG-91707 Change-Id: Ia1e7240b4ce240c1c44f00ca680717d182df7550 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 9f13842fe61541cb8ab9822174ea963e418b5537) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Resurrect data moves in QListAndrei Golubev2021-04-261-11/+10
| | | | | | | | | | | | | | | | | | 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) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Restore pre-Qt6 QList::fill() behaviorAndrei Golubev2021-02-101-1/+4
| | | | | | | | | | | | | | | | | | | Somehow QList::fill(t, newSize) introduced a regression in Qt6: when newSize < QList::size() we should resize to the newSize. This is aligned with QVector::fill() in 5.15 and std::vector::assign() While 6.0 is already out, picking it to 6.0.x could save someone who haven't migrated yet as well as fix some accidental bugs in Qt's code [ChangeLog][QtCore][QList] Fixed QList::fill() regression introduced in 6.0: calling fill() with size < current list size wouldn't truncate the list Fixes: QTBUG-91042 Change-Id: Ic166e2c5e42390b61df1030f7c705e344433f7f2 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 6512a7fc642c65455db770385c67cfa6d71c294c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Mark places where we missed conversion to unicode character typesEdward Welbourne2021-01-081-0/+1
| | | | | | | | | | | We should use char32_t for the toUcs4() methods of QString and QStringView and use char16_t for QString::utf16(), thereby matching QStringView. These naturally imply knock-on changes in various places. Unfortunately, we didn't make those changes in Qt 6, so they'll have to wait for Qt 7. Change-Id: I18451d4b31b76658092e19d3fcbc8bc0fe5ce307 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QList: make an indirect inclusion directGiuseppe D'Angelo2020-12-041-0/+1
| | | | | Change-Id: Ief36ac375f5c26b4a5de6bc18ee3f2f777051024 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Sequential general purpose containers: add erase/erase_ifGiuseppe D'Angelo2020-12-011-22/+22
| | | | | | | | | | | | | | | | | | | | This is refactor/revisit for Qt 6 of the original commit [1] by Marc, limited to QList and QVLA. [1] see 11aa9a2276ba5367adbbd96d0ba13111d58145f8 [ChangeLog][QtCore][QList] Added erase() and erase_if(), for consistent container erasure. Added removeIf() as a method, complementing removeOne() / removeAll(). [ChangeLog][QtCore][QVarLengthArray] Added erase() and erase_if(), for consistent container erasure. Added removeIf() as a method, complementing removeOne() / removeAll(). Change-Id: I2499504e221431ead754dd64cc8a4d4e9f116183 Done-by: Marc Mutz Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Move the iterator from QTypedArrayData to QListLars Knoll2020-11-171-12/+78
| | | | | | | | | | The low level implementation does not use it at all, so there's no point having the iterator in QTypedArrayData. Having it in QList removes and indirection and will lead to clearer error messages. Change-Id: I4af270c3cdb39620e5e52e835eb8fe1aa659e038 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Clean up QList(iterator, iterator)Lars Knoll2020-11-171-11/+14
| | | | | | | | | | Fold the two overloads into one, and distinguish the cases using if constexpr. Do not overload QArrayOps::copyAppend(), to make it clear which one is being used. Change-Id: If6a894841aacb84ba190fb2209246f5f61034b42 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix signature of QArrayDataOps::erase()Lars Knoll2020-11-171-3/+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>
* Remove the special code for emplaceFront/Back againLars Knoll2020-11-171-2/+2
| | | | | | | | | emplace() itself now handles those cases fast enough, so there should not be a need to add special code paths for those methods. Change-Id: I3277eb77dd54194e46f96f24de44d7785a6f860a Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add a couple of noexcept to methods that can't throwLars Knoll2020-11-171-18/+18
| | | | | | | | | | | | | Trivial methods that don't modify any data for the most part. Also mark removeFirst/Last() as noexcept. Those methods can't throw exceptions as we require ~T() to be noexcept. Change-Id: I8698705c6113909aa8f7ae021a932df48a224d5d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move emplaceFront/Back() implementation into QArrayDataOpsLars Knoll2020-11-171-16/+2
| | | | | | | | This simplifies and clean up the code. Change-Id: I4cbfa69bda95187f97daf814eb3d44d90c502d92 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Simplify the code for QList::emplace()Lars Knoll2020-11-171-19/+1
| | | | | | | | | | | | Unify it with the code in QArrayDataOps and only have one emplace method there that handles it all. Adjust autotests to API changes in QArrayDataOps and fix a wrong test case (that just happened to pass by chance before). Change-Id: Ia08cadebe2f74b82c31f856b1ff8a3d8dc400a3c Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify reallocation handling in QListLars Knoll2020-11-171-70/+29
| | | | | | | | | | Have one generic method for detaching and reallocations. Use that method throughout QList to avoid duplicated instantiations of code paths that are rarely used. Change-Id: I5b9add3be5f17b387e2d34028b72c8f52db68444 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Smaller code cleanups in QListLars Knoll2020-11-171-11/+10
| | | | | | | | | | Some cosmetics, but also some optimizations where we avoid a temporary copy, or calling detach() twice. Change-Id: I26803fdecf943ed9fab9baf58124091c7cebe1f3 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>
* QList::append(QList) doesn't require a temp copyLars Knoll2020-11-171-3/+1
| | | | | | | | | | The method can simply forward to the append overload taking iterators. That method is safe against the iterators being part of the list itself. Change-Id: I4bebd6c1118cd4a428fa9248235029b997ef60b2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Fix error on MSVC when QList with disabled rvalues is instantiatedLars Knoll2020-11-161-6/+32
| | | | | | | | | | | MSVC does in some case full instantiation of the template. Make sure all of it expands to valid C++, even in the case where those methods are supposed to be disabled. Fixes: QTBUG-86289 Change-Id: Iaae39ef60fc5cf5fee273b0934a5a52b6ae4ec17 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Do not shrink on remove()Lars Knoll2020-11-091-16/+5
| | | | | | | | | | This is in line with Qt 5 behavior, how std::vector works and also how QString and QByteArray behave. If you need the shrink allocated storage, call squeeze() manually. Change-Id: I16cadd4f2a89bb2ec5de02fe69186f5da321cd06 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Implement fast paths for removeFirst() and removeLast()Lars Knoll2020-11-091-2/+20
| | | | | | | | | This avoids lots of the code and checks in remove() making the methods a lot faster. Change-Id: If99c39f5b55672b341f9331b5903bf77e9e67477 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Rename AllocationPosition enum and its membersLars Knoll2020-11-041-6/+6
| | | | | | | Use GrowsAt* and GrowthPosition as that is clearer. Change-Id: I3c173797dec3620f508156efc0c51b4d2cd3e142 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Properly implement emplaceBack/Front() in QArrayDataOpsLars Knoll2020-11-041-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the performance of QList<QString>::append/prepend() and we now beat QVector in Qt 5. QList from Qt 5 is still a bit better for QString, but this might be related to the fact that QString in Qt 6 is larger than in Qt 5. Appending 20M integers to the list gives: Qt 6: 35ms Qt 5.15/QVector: 99ms Qt 5.15/QList: 78ms Appending 20M QStrings to the list gives: Qt 6: 172ms Qt 5.15/QVector: 194ms Qt 5.15/QList: 136ms Appending 20M structs of three pointers gives (100M will crash in Qt5 as 100M*24bytes overflows): Qt 6: 109ms Qt 5.15/QVector: 272ms Qt 5.15/QList: 469ms Prepending 20M integers to the list gives: Qt 6: 58ms Qt 5.15/QList: 90ms Prepending 20M QStrings to the list gives: Qt 6: 448ms Qt 5.15/QList: 147ms Prepending 20M structs of three pointers gives (100M will crash in Qt5 as 100M*24bytes overflows): Qt 6: 267ms Qt 5.15/QList: 435ms No numbers for prepending to a QVector in 5.15 as the operation was O(n) there. The difference in time between append and prepend comes from the fact that our growth policy favors appending to some extent. Change-Id: Ice4598df5ca408413bfb00f5fe05e0b8d512623d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Introduce QADP::reallocateGrow()Andrei Golubev2020-11-041-4/+16
| | | | | | | | | | | | | | Added realloc() code path to QMovableArrayOps Implemented fast realloc() based growing for QADP and used it in QList::emplaceBack. This gives quite a bit of speedup and shows better results than 5.15 at 100k+ iterations of "list.append(elem)", meanwhile also closing a gap between movable types Task-number: QTBUG-87330 Change-Id: I42fc182ecd93c85600dac622385152fc57735da8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Implement QList::emplaceBack as a proper functionAndrei Golubev2020-11-041-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | My endeavours figuring out why QList::append(elem) gives worst performance compared to 5.15 ended up into this commit. After some straightforward fixes, what was left is "everything is uniformly worse" and takes more CPU cycles Introduce emplaceBack implementation as append is quite a special case that could be greatly simplified. This is a "straightforward" part of the optimizations While at it, change append(t) to use emplaceBack(t) For workloads like: QList<int> list; forever { list.append(0); } this gives huge improvement (roughly 30% for 10k+ elements), movable and complex types also get a tiny speedup Task-number: QTBUG-87330 Change-Id: I9261084e545c24e5473234220d2a3f2cd26c2b7f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Move insert() operation into QArrayDataOpsLars Knoll2020-11-041-23/+1
| | | | | | | | | 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-19/+17
| | | | | | | | | | 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>
* Avoid expensive iterator calculations in append()Lars Knoll2020-11-041-37/+29
| | | | | | | | | | | | | 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>
* Remove unused parameterLars Knoll2020-11-041-4/+4
| | | | | | Change-Id: Idceb7ee3ce752b62ed6800b0a1004832a4c48af7 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add QList::emplaceFront() that fixes huge performance issue in prependAndrei Golubev2020-11-041-9/+28
| | | | | | | | | | | | | | | | | | | | | | Prepend in QList was using insert() logic that always uses append-aware functions. This results in the fact that freeSpaceAtBegin() is always 0 and forces us to actually allocate on *every* call (with the same capacity!). Vicious cycle is hot-fixable with introduction of emplaceFront (or anything prepend-aware, really) This brings me from 632ms to 0.65ms for 100k iterations of list.prepend(int(0)). Still ~3x worse than QList in 5.15 but much faster than QVector, which takes 382ms in the same workload Not addressed: - QString/QBA - Other prepend functions in QList e.g. prepend(it1, it2) - Lower-level array operations that should just be extended Task-number: QTBUG-86583 Change-Id: Ie82b07d81a67605cd308d9fabf9532d57935647f Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Hide QList comparisons from ADLAllan Sandfeld Jensen2020-10-301-62/+48
| | | | | | | | | | Makes them member methods instead of hidden inline, as those actually gets listed in documentation, and two were already documented as such. Task-number: QTBUG-87975 Change-Id: I382ff8b701753f1fe150a38f4c530a52c98ad292 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QList: also default count()'s template parameterGiuseppe D'Angelo2020-10-261-1/+1
| | | | | | | | Also fix the docs. Change-Id: If08116cb8657d00d610de9451be0ba73ce19dcd1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Update QList::append(const_reference) -> QList::append(parameter_type)Andrei Golubev2020-10-241-1/+1
| | | | | | | | | | Forgotten during previous round of replacing const lvalue references with parameter_type in QList methods Task-number: QTBUG-86553 Change-Id: I9abda4db3b504521b64fab1f220559c36bfeb9f5 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QList/QVLA: default the parameter for indexOf/contains/remove/etc.Giuseppe D'Angelo2020-10-231-5/+5
| | | | | | | | This allows to use list-initialization when calling these functions, for instance list.removeAll({}). Change-Id: I2828d900a44bd0bc5aea5fba4777304b09190bc9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QList: make (last)IndexOf and contains function templatesGiuseppe D'Angelo2020-10-231-14/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There's no reason why they shouldn't be; one might want to do a lookup passing an object which is comparable with the list's value type (e.g. search with a QByteArrayView needle into a QByteArrayList haystack). Insofar we've had to add overloads to QListSpecialMethods for all these cases, which clearly doesn't scale and creates top-tier and low-tier lists. There is one downside, namely, calling QList<A>::indexOf(B) for a B for which there isn't an operator==(A, B) but only a conversion towards A. Before, B was converted only once (at call site), now it's converted at every call of operator==. In general: such types are broken and should be fixed on their own. However let's avoid a possible regression in client code, so I've left the QString overloads in QStringList in. To get there: centralize the implementation of those methods in a empty base class, which gets then inherited by QListSpecialMethods, which is inherited by QList. This is there are still special methods that may want to overload contains, e.g. QStringList which also passes a case sensitivity). The only breakages comes from code that was already broken, for instance mixing signed and unsigned types, and the beauty of this is that now we *detect* that instead of silently ignoring. QVLA and other QList methods will be tackled in future commits. [ChangeLog][QtCore][QList] The indexOf, lastIndexOf and contains methods now take an object of any datatype -- and not just the list's own value type. This allows for heterogenous lookup in QLists. Change-Id: Ib34812217eb2b0f926fad1fc195b33758196941c Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use parameter_type in QList methodsAndrei Golubev2020-10-221-13/+13
| | | | | | | | | QList::parameter_type is defined and used to give better performance e.g. for arithmetic types. Let's use it consistently in QList API instead of const T & Change-Id: I2e12bd83f55679b55a14fbb23ab6172a9cf7bbcc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Whitespace cleanup in corelib/toolsAllan Sandfeld Jensen2020-10-211-1/+1
| | | | | Change-Id: Ibe796c398a8e5488b7203abb07aa54740744f1ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Convert QList alias definitions to 'using'Andrei Golubev2020-10-201-18/+28
| | | | | | | | | | | | Modern syntax for type aliases looks much nicer and is easier to read. Additionally, QDoc is able to generate better documentation for 'using' based aliases. Also, aliases are simplified for QDoc Task-number: QTBUG-86553 Change-Id: I44932fbd94f32c1463eafedd1b48c1e840b697e3 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix QDoc warnings for QList/QVectorAndrei Golubev2020-10-201-0/+10
| | | | | | Task-number: QTBUG-86553 Change-Id: Iac944c78640bfcfb6ee137c0ef3dd89387700b4c Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QList::removeOne: make it generic as wellGiuseppe D'Angelo2020-10-201-1/+2
| | | | | | Change-Id: I0c50b2ae76f9d0f053b3d5b1ab98d12e0524e419 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QList::removeAll: make it genericGiuseppe D'Angelo2020-10-201-3/+11
| | | | | | | | | | | | | | | | | | | | This is a bit more tricky than expected because we support passing references to objects that are into the list itself (for instance, list.removeAll(list.front())). For those objects we have to take copies. This is fine, but the moment we make the function generic, that's going to fail when passing arguments of types that cannot be copied, such as arrays (e.g. stringList.removeAll("hello")). For those, keep a reference, as they cannot be aliases into the list anyhow. [ChangeLog][QtCore][QList] The removeAll and removeOne methods now take an object of any datatype -- and not just the list's own value type. This allows for heterogenous removal inside QLists. Change-Id: I0c447770bbc7ff0ff4bb4c0e35081414c5ff963e Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QADP capacity functions use qsizetype instead of size_tAndrei Golubev2020-10-081-6/+6
| | | | | | | | | | | | | | | 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>
* QList: don't detach on squeeze when holding raw dataMårten Nordheim2020-09-301-1/+3
| | | | | | | | | To match QString and QByteArray behavior Change-Id: Ifce4a5dee6fc9077e855a24499f11f911e359cf5 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QList: Remove CapacityReserved on squeezeMårten Nordheim2020-09-301-0/+3
| | | | | | | | | | Even if we don't reallocate or detach. Change-Id: I44928c261f037b304de8ee6135b96f00dd217c51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Fix a bunch of qdoc warnings from QList typesVolker Hilsheimer2020-09-211-0/+6
| | | | | | | | | | For documentation purposes, we treat QList, QByteArrayList, and QStringList as simple classes, whereas reality is a bit more complicated. We conditionally change the declaration of the types for qdoc runs, and need to be consistent to avoid a flood of warnings from clang when building documentation. Change-Id: I22d529079e10f8fd3d93edc771e5f05729fa925f Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Make QStringList an alias to QList<QString>Lars Knoll2020-09-121-16/+27
| | | | | | | | | | | | | | | | | | Fix our API, so that QStringList and QList<QString> are the same thing. This required a bit of refactoring in QList and moving the indexOf(), lastIndexOf() and contains() method into QListSpecialMethods. In addition, we need to ensure that the QStringList(const QString&) constructor is still available for compatibility with Qt 5. Once those two are done, all methods in QStringList can be moved into QListSpecialMethods<QString>. Change-Id: Ib8afbf5b6d9df4d0d47051252233506f62335fa3 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QList/QString/QByteArray: no prepend optimized allocation when emptyAndrei Golubev2020-09-071-4/+3
| | | | | | | | | | | | | | | | | | Scoped prepend optimized allocation to only work when prepending into a non-empty container. Otherwise, even appends would be considered prepends since d.size == 0 when container is empty This is, of course, not good for prepend cases but we prefer appends over prepends. My proposal is to figure out what's the best strategy based on use cases and performance measurements. For now, let's just make sure appends are not additionally pessimized Anyhow, this is an implementation detail and should not be considered behavior change (at least not the one that is user noticeable) Task-number: QTBUG-84320 Change-Id: Ibed616a2afa9bc24f78252f15a617bf92e2c6ea3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QList/QByteArray/QString: Base GrowsBackwards heuristic on old sizeMårten Nordheim2020-09-031-2/+2
| | | | | | | | | | | If you grow from 10 to 100 characters then even if the point of insertion was the end then it will get the GrowsBackwards option on realloc. By basing it on the oldSize the intention of the position to insert at is better clarified. Change-Id: Ia73f4902e8356d94709556de5704cbfa0e1a3a56 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString/QList: disregard space at front during reserve()Andrei Golubev2020-09-021-2/+2
| | | | | | | | | | Aligned QString, QList to the new agreed upon behavior Aligned QList::resize() along the way to be consistent with QString/QBA Task-number: QTBUG-84320 Change-Id: Ie9d7b4b6ebe54bd373af78d92906144b383bbfe2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Update allocation interface of QArrayDataPointerAndrei Golubev2020-08-271-6/+4
| | | | | | | | | | | | | Added overload to allocGrow that figures the capacity to allocate from the newSize argument passed. This is useful in QList (and likely in other places) Fixed QArrayPodOps::reallocate as a drive by: don't call memmove when it is not needed Task-number: QTBUG-84320 Change-Id: I67efe55a60efaf3ab6057b0249d6a446e04a09e3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Support GrowsBackwards prepend in QListAndrei Golubev2020-08-271-12/+10
| | | | | | | | | | | | | Restored previously deleted logic of setting GrowsBackwards flag for prepend-like cases. This should be sufficient to fully enable prepend optimization Fixed QList::emplace to not use implementation detail logic. Updated tests to cover changed behavior and its correctness Task-number: QTBUG-84320 Change-Id: I4aadab0647fe436140b7bb5cf71309f6887e36ab Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Support GrowsBackwards flag in QArrayDataPointerAndrei Golubev2020-08-271-11/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | Introduced allocation function in QArrayDataPointer with interface similar to QArrayData::allocate that supports growing strategies. This func is used instead of the original in cases when prepend-aware storage is needed. Tried to follow Qt5 QList policy in terms of space reservation Updated QPodArrayOps::reallocate to be aware of growing shenanigans. It doesn't look like a perfect solution but it is rather close and similar to what Qt6 QList is doing when not growing (e.g. reserve/squeeze) Added initial QCommonArrayOps with helper function that tells when reallocation is preferable over just using the insert-like operation. This comes up later on when GrowsBackwards policy is properly supported in operations Essentially, 2/3 main data management blocks for prepend optimization are introduced here. The last one being a generalized data move that is done instead of reallocation when existing free space is not enough Task-number: QTBUG-84320 Change-Id: I9a2bac62ad600613a6d7c5348325e0e54aadb73d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>