summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvarlengtharray.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch 'origin/5.13' into 5.14Liang Qi2019-09-301-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/global/qrandom.cpp src/corelib/io/qfileinfo.cpp src/corelib/kernel/qeventdispatcher_win.cpp src/corelib/kernel/qeventdispatcher_win_p.h src/gui/text/qfontdatabase.cpp src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm src/plugins/platforms/windows/qwindowsglcontext.cpp src/testlib/qtestcase.cpp Done-With: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Done-With: Edward Welbourne <edward.welbourne@qt.io> Change-Id: I4893212471aa24be804c989a581810e2f714545c
| * QVarLengthArray: Avoid int vs. size_t warnings in operator=Laszlo Agocs2019-09-291-1/+1
| | | | | | | | | | Change-Id: I879b62c55e4211d3e4e1a18f6699f26e3f5de1f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QVector/QList/QLinkedList/QVarLengthArray/QSet: add missing deduction guidesMarc Mutz2019-08-071-0/+7
| | | | | | | | | | | | | | | | | | | | | | Amends 2e1763d83a1dacfc5b747934fb77fa7cec7bfe47. The new range ctors need deduction guides, since the compiler can't deduce the value_type from a pair of iterators. Change-Id: I3ec1e5f91305b317c443b6a70246be416b55bad9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QVarLengthArray: optimize pop_back()Marc Mutz2019-07-141-1/+3
| | | | | | | | | | | | | | | | | | | | Don't call realloc() with all its machinery when we know exactly what to do: destroy the last element and decrease the size by one. Extend the test, removing the unused Foo class for a new Tracker one. Change-Id: I568eef4f6335669689fb16fd23af92cb4d6464bd Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Make the default ctor of QVarLengthArray implicitUlf Hermann2019-07-021-1/+3
| | | | | | | | | | | | | | | | | | Otherwise "QVarLengthArray<Foo> x = {};" gives a warning. Also, some compilers get confused about "QVarLengthArray()" this way. Task-number: QTBUG-76199 Change-Id: I4296586c0181d3e6e82ca8b7b79aeb9a21645d1f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | QVarLengthArray: add qHash overloadGiuseppe D'Angelo2019-06-231-0/+8
| | | | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][QVarLengthArray] Added a qHash overload. Change-Id: I771203ae3bb575b49f70e9114287dd2690031b42 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Remove handling of missing Q_COMPILER_INITIALIZER_LISTSAllan Sandfeld Jensen2019-05-021-9/+3
| | | | | | | | | | | | Change-Id: Id65b39c787235a051262544932e6717d076f1ea0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Non-associative containers: add range constructorsMarc Mutz2019-04-171-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Something nice we'd like to detect for array-backed containers is if the iterator passed is a Contiguous one; if the type is also trivially copyable / Q_PRIMITIVE_TYPE, we could memcpy() the whole range. However, there's no trait in the Standard to detect contiguous iterators (the best approximation would be detecting if the iterator is actually a pointer). Also, it's probably not smart to do the work now for QVector since QVector needs refactoring anyhow, and this work will be lost. QString and QByteArray are left in another commit. [ChangeLog][QtCore][QVector] Added range constructor. [ChangeLog][QtCore][QVarLengthArray] Added range constructor. [ChangeLog][QtCore][QList] Added range constructor. [ChangeLog][QtCore][QStringList] Added range constructor. [ChangeLog][QtCore][QLinkedList] Added range constructor. [ChangeLog][QtCore][QSet] Added range constructor. Change-Id: I220edb796053c9c4d31a6dbdc7efc5fc0f6678f9 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
* | Remove remaining Q_DECL_NOEXCEPT/Q_DECL_NOTHROW usageAllan Sandfeld Jensen2019-04-041-4/+4
|/ | | | | Change-Id: I91ac9e714a465cab226b211812aa46e8fe5ff2ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix UB (invalid pointer comparison) in QList, QVector, QVLAMarc Mutz2018-10-081-1/+2
| | | | | | | | | | | | | | | QList, QVector and QVarLengthArray check the validity of iterators passed to member functions using isValidIterator(), which checks that the underlying pointers are in the range [begin, end]. This check is well-defined when the outcome is positive, ie. when the iterator is valid. But if the iterator is not valid, and does not happen to point into [end, begin + capacity], the comparison, which uses normal operator<, invokes UB. Fix by using std::less<T*>, which defines a total ordering. Change-Id: I1e5757789b4b9779f5e3e298e7f2b2dd0b27576c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cast away -Wclass-memaccess warnings in QVarLengthArray methodsEdward Welbourne2018-08-201-3/+3
| | | | | | | | | | | | With g++ 8.2.0, I get warnings when a QVarLengthArray<QString> calls remove() or prepend(), as some tests in tst_QVarLengthArray do, as they call memmove() "writing to an object of type ‘class QString’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead"; which may indeed be a good argument for not using QVarLengthArray<QString>, but its own tests do. Change-Id: I4f8a64948b32a54e67a285df4ec7788f60739ffb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* fixup oversight in rvalue overloads of operator+=() and operator<<()Eric Lemanissier2018-03-261-2/+2
| | | | | | | ammends 4dee5446bee9c7417bf6f5dc44294a0b7238a9ba Change-Id: Ia0ca27644eb71815a93d6e76681b8a9e61a4e7ab Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Add missing rvalue overloads of operator+=() and operator<<()Christian Ehrlicher2018-03-071-0/+4
| | | | | | | | | | | | | | | They were forgotten when the overloads for append()/push_back() were added in Qt 5.6 [ChangeLog][QtCore][QVarLengthArray] Added missing rvalue overload of operator+=() and operator<<() [ChangeLog][QtCore][QVector] Added missing rvalue overload of operator+=() and operator<<() Change-Id: I20fedfba2bf282773bd1f9cf2c8ec06f05896a7d Reviewed-by: Martin Smith <martin.smith@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Merge remote-tracking branch 'origin/5.9' into 5.11Liang Qi2018-02-141-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .qmake.conf src/corelib/animation/qvariantanimation.cpp src/corelib/global/qglobal.cpp src/corelib/global/qlogging.cpp src/corelib/io/qprocess_win.cpp src/corelib/json/qjsonarray.cpp src/corelib/tools/qsimd_p.h src/corelib/tools/qtimezoneprivate_p.h src/corelib/xml/qxmlstream_p.h src/gui/kernel/qsimpledrag.cpp src/gui/kernel/qsimpledrag_p.h src/plugins/generic/generic.pro src/plugins/platforms/cocoa/qcocoamenu.mm src/widgets/styles/qmacstyle_mac.mm tests/auto/concurrent/qtconcurrentmap/BLACKLIST tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp tests/auto/gui/kernel/qwindow/BLACKLIST tests/auto/widgets/dialogs/qmessagebox/BLACKLIST Change-Id: I508d686cf20f7f8cc6a7119b9bc7c3bbb505c58e
| * Silence GCC 8 warning on memcpy of movable typesThiago Macieira2018-02-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This is similar to commit 342bb5b03a76d1428fafb8e1532d66e172bd1c0b. From GCC 8: qarraydataops.h:84:17: error: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘class QStringRef’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess] [etc.] Change-Id: I41d006aac5bc48529845fffd150e817e64973bec Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Add rvalue overload of insert/prepend to QVarLengthArray and QVectorAllan Sandfeld Jensen2018-01-201-2/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improves performance and STL compatibility by adding rvalue versions of prepend and insert. [ChangeLog][QtCore][QVarLengthArray] Added rvalue overloads of prepend and insert. [ChangeLog][QtCore][QVector] Added rvalue overloads of prepend and insert. [ChangeLog][QtCore][QVarLengthArray] Can now contain movable but non-copyable types, such as std::unique_ptr. Change-Id: I6c946acc5b67502c91c52ac5dea67cedb1af93a5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Array-backed containers: add shrink_to_fit for STL compatibilityGiuseppe D'Angelo2017-04-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Side note: QHash has squeeze(), but there's no shrink_to_fit on std::unordered_map. [ChangeLog][QtCore][QByteArray] Added shrink_to_fit(). [ChangeLog][QtCore][QString] Added shrink_to_fit(). [ChangeLog][QtCore][QVarLengthArray] Added shrink_to_fit(). [ChangeLog][QtCore][QVector] Added shrink_to_fit(). Change-Id: Ifd7d28c9bed70727be6308f0191a188201784f61 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Merge remote-tracking branch 'origin/5.9' into devLiang Qi2017-03-281-0/+1
|\| | | | | | | | | | | | | | | | | Conflicts: examples/examples.pro tests/auto/corelib/tools/qchar/tst_qchar.cpp tests/auto/other/qaccessibility/accessiblewidgets.h Change-Id: I426696c40ab57d14dc295b8103152cede79f244c
| * Merge remote-tracking branch 'origin/5.8' into 5.9Liang Qi2017-03-271-0/+1
| |\ | | | | | | | | | Change-Id: Icdd71e9713725bda9c305e338f5c8b41a92ed8e8
| | * QVarLengthArray: fix compilation with GCC 7Marc Mutz2017-03-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a warning-turned-Werror in qdistancefield.cpp: In member function ‘void QVarLengthArray<T, Prealloc>::realloc(int, int) [with T = bool; int Prealloc = 256]’, inlined from ‘void makeDistanceField(QDistanceFieldData*, const QPainterPath&, int, int)’ at ../../include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qvarlengtharray.h:275:10: ../../include/QtCore/../../../../qt5/qtbase/src/corelib/tools/qvarlengtharray.h:390:19: error: ‘void* memcpy(void*, const void*, size_t)’: specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] memcpy(ptr, oldPtr, copySize * sizeof(T)); ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Apparently GCC cannot rule out that copySize may be negative in the call to memcpy. Put GCC on the right track by adding a Q_ASSUME. Change-Id: I63e3801e52ebe2a7f77e3a97ef03ec3869319c8c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | | Remove unused QPodList classMarc Mutz2017-03-221-4/+0
|/ / | | | | | | | | | | | | | | It's private API, the last in-tree user was removed in acbd7999, but failed to remove the class. Do it now. Change-Id: I26294b535d80b419a2f545a4783014b493a5dc93 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | QVarLengthArray: add rvalue overload of append/push_backMarc Mutz2017-02-251-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improves performance when appending temporaries, esp. since the aliasing fix in the lvalue overload in 0f730ef made that overload correct, but a bit slower across reallocs. The unit tests already also pass rvalues, so the function is covered in the existing tests. [ChangeLog][QtCore][QVarLengthArray] Added rvalue overloads of append() and push_back(). Change-Id: If3a6970f03a160cba5b42d33d32d3d18948f6ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Merge remote-tracking branch 'origin/5.8' into 5.9Liang Qi2017-02-241-5/+15
|\| | | | | | | | | | | | | Conflicts: mkspecs/features/moc.prf Change-Id: Ia71c8e3b3185f7c999bf226d0675051b10b8740b
| * QVarLengthArray: fix appending an already-contained itemMarc Mutz2017-02-171-5/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Like the lvalue QVector::append() overload, when we reallocate, we need to take a copy of the function's argument because the reference will get stale upon reallocation. Add a test. [ChangeLog][QtCore][QVarLengthArray] Fixed a bug involving appending an item already in the container to the container again. Change-Id: I06eeed6cb383dd5924e47a302bb3d1666d04c8e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Do not use QTypeInfo::isStatic anymoreMarc Mutz2017-02-221-2/+2
|/ | | | | | | | | | | | | | | | ... except in QList. When dafa3618 introduced isRelocatable and QTypeInfoQuery, the intention was to decouple the memory layout of QList from the reallocation optimizations in QVector. This never happened, as QVector (and QVarLengthArray) continue to use isStatic to this day. Fix by porting both QVector and QVLA to QTypeInfoQuery and isRelocatable. Change-Id: I6951f2cf21f0cbb24e2dbd38f80f1bd82007d394 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix possible loss of data warningJesus Fernandez2017-01-241-1/+1
| | | | | | | | warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data while compiling class template member function 'QVarLengthArray<T,Prealloc>::QVarLengthArray(std::initializer_list<T>)' Change-Id: I36f5ef65ec1f511eac7f3ad1a4717d18f7dc9ce4 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Don't crash on QVLA construction from an empty std::initializer_listThiago Macieira2016-12-091-1/+2
| | | | | | | | | | | | | | | | | | | | | The C++ standard says in [support.initlist.access]/1: constexpr const E* begin() const noexcept; Returns: A pointer to the beginning of the array. If size() == 0 the values of begin() and end() are unspecified but they shall be identical. So we can't assume it's non-null. I didn't want to remove the Q_ASSERT, so passing a non-null pointer to append() remains required. This patch simply won't call append() if the initializer list is empty. This was already tested, but the failure is with a compiler that is not part of the Qt CI. Task-number: QTBUG-57277 Change-Id: Iaeecaffe26af4535b416fffd1489806872b412ee Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-04-291-3/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: mkspecs/features/qml_module.prf mkspecs/features/qt_common.prf src/gui/text/qzip.cpp src/plugins/platforms/cocoa/qnsview.mm src/plugins/platforms/windows/array.h src/testlib/qtestcase.cpp src/widgets/dialogs/qfilesystemmodel.h Change-Id: Ie41c5868415b81f7693c80e045497035504bb210
| * Silence MSVC warnings when using certain std algorithmsMarc Mutz2016-04-261-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The MSVC STL warns when passing naked pointers as non-bounded iterators to algorithms such as std::equal and std::copy, in an attempt to inform users that the range specified by that iterator has an implicit minimum size that the caller of the algorithm must ensure is met: warning C4996: 'std::_Equal1': Function call with parameters that may be unsafe - \ this call relies on the caller to check that the passed values are correct. To \ disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to \ use Visual C++ 'Checked Iterators' When building Qt, as well as when building user projects with qmake (cf. 0a76b6bc7f98900ea884cd10ccca1a332e5bdba5), we globally disable this warning (with -D_SCL_SECURE_NO_WARNINGS), but since we started using STL algorithms in public headers (e.g. in qvector.h), users get this warning in their own projects now, unless they, too, define said macro. But such a requirement is against the Qt policy to have headers that are warning-free as much as possible. The suggested way of fixing this warning is to wrap the naked pointer in a stdext::unchecked_array_iterator before passing it to the algorithm, cf. examples in https://msdn.microsoft.com/en-us/library/ttcz0bys%28v=vs.120%29.aspx or, together with the capacity-made-explicit, in a stdext::checked_array_iterator. To avoid ifdefs for platforms that don't have these extensions (which, incidentally, for the unchecked case, includes MSVC 2012), wrap the calls in macros. The end game here is to drop -D_SCL_SECURE_NO_WARNINGS, at least for public headers, even though this commit also adds the wrapper to implementation and private header files. An alternative to the wrapper would have been the version of std::equal that takes four iterators. However, that is a C++14 library feature, while this version of Qt still needs to compile with a C++98 compiler, and, more importantly, there isn't, and never will be, a corresponding 4-iterator version of std::copy. Task-number: QTBUG-47948 Done-with: Stephen Kelly <steveire@gmail.com> Change-Id: I1bbab257fb5f1c5042939c382a412b596112ff26 Reviewed-by: Stephen Kelly <ske@ableton.com>
* | Updated license headersJani Heikkinen2016-01-151-14/+20
|/ | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.5' into devLiang Qi2015-04-061-0/+9
|\ | | | | | | Change-Id: If9fd98525b6b4ca07e5e006fc98bf372a73b8a21
| * QVLA: Add operator= for initializer listsKai Koehne2015-04-041-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a dedicated operator=(std::initializer_list) that first resizes the QCLA, and then replaces the elements one by one. This should be usually faster than creating a temporary QCLA and then copying it, except for the case where the new array does not fit into the allocated stack - but this is IMO nothing to optimize for. Task-number: QTBUG-45041 Change-Id: I147d6d01186b1ca3c635b2c8365d8f6e638ce6fe GPush-Base: 08de3113051e1289f0de0651ec5647c9ee6feb27 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QVarLengthArray: add {const_,reverse_iterator}, {c,}r{begin,end}()Marc Mutz2015-04-051-0/+9
| | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][QVarLengthArray] Added rbegin(), crbegin(), rend(), crend(), and reverse_iterator and const_reverse_iterator typedefs. Task-number: QTBUG-25919 Change-Id: Ifda5d420802a3594c3181f54036279f16a7da16e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QVarLengthArray: add relational operators <,<=,>,>=Marc Mutz2015-04-051-0/+30
|/ | | | | | | | | | std::vector has them, too. [ChangeLog][QtCore][QVarLengthArray] Added relational operators <, <=, >, >= if the element type supports operator<. Change-Id: I69e16d361fd4738a56b292ebfa78316d28871eda Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: Do not require operator!= for element comparisonKai Koehne2015-03-231-5/+4
| | | | | | | | | | The documentation claims that operator== is needed, not operator!=. While at it, we can also replace the loop with std::equal, which might even allow STL implementations to choose a hand-optimized version of the algorithm for C++ builtin types ... Change-Id: I988b326d6af3b767526952e303468e18ff6594f9 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* QVarLengthArray: Add initializer_list constructorKai Koehne2015-03-231-0/+11
| | | | | | | | | | | | | | | | | Implement an initializer_list constructor, which was probably just forgotten so far. Technically this is a SC incompatible change, since QVarLengthArray<int> array = {10}; will now create an array with one element 10, instead of an empty array with a reserved size of 10. Anyhow, keeping the inconsistency with the STL / other Qt containers here would certainly do more harm than good in the long run. Task-number: QTBUG-45047 Change-Id: I4675880f93e141181250939942fa32300916b0e3 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Add QVarLengthArray::{indexOf,lastIndexOf,contains} functionshjk2014-01-091-0/+49
| | | | | | | | | | [ChangeLog][QtCore][QVarLengthArray] Added the indexOf, lastIndexOf and contains functions to QVarLengthArray. These functions make the class more similar to QVector. Change-Id: I9bd2b22bd8b7151c2d17aede36e5f2126570600b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Remove redundant checks in some tools classesJędrzej Nowacki2013-09-131-2/+2
| | | | | | | | | | | | | | | | | | | | This is a simple optimisation allowed to us by the fact that all platforms we run on use two's complement for the signed integers. The trick works as long as one of the two signed integers is known beforehand to be non-negative: - by definition, for any signed integer i, i <= INT_MAX - by definition, for any unsigned integer u, u >= 0 - given a signed integer x >= 0, 0U <= uint(x) <= uint(INT_MAX) - therefore, given another signed integer y of whatever value, uint(x) < uint(y) ←→ x < y && y >= 0 The trick is an optimisation because the compiler doesn't know that one of the two sides is always non-negative. Otherwise, it would do the same optimisation. Change-Id: If256ec0df4e06335805af8010bb67ce5fd3e065a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove qCopy from QVarLengthArrayGiuseppe D'Angelo2013-09-041-1/+2
| | | | | | | | QtAlgorithms is getting deprecated, see http://www.mail-archive.com/development@qt-project.org/msg01603.html Change-Id: I854f64ebd6d83718b1bcb3c70a1697e38243296c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray - check if iterators arguments are valid (in debugmode)Thorbjørn Martsum2013-07-121-0/+10
| | | | | | | This add checks on iterators on insert and erase. Change-Id: I41d96e038d74668cc1df10b6d42cde4b82f8a696 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Prevent negative size in QBitArray, QVector and QVarLengthArray ctors.Mitch Curtis2013-06-051-0/+2
| | | | | | | | | | | | | | | | | | As shown in QTBUG-24345, QBitArray will exhibit invalid reads when initialised with a negative size and run under valgrind. QVector and QVarLengthArray both cause a crash if initialised with a negative size. This patch enforces sizes greater than or equal to 0 with asserts and existing if statements, and hence impose no performance penalty for release builds. Task-number: QTBUG-24345 Task-number: QTBUG-30037 Change-Id: I9a969f6016e0a59904a60bbfe9e5360e6f523b87 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QT_{BEGIN,END}_HEADER macro usageSergio Ahumada2013-01-291-4/+0
| | | | | | | | | | | The macro was made empty in ba3dc5f3b56d1fab6fe37fe7ae08096d7dc68bcb and is no longer necessary or used. Discussed-on: http://lists.qt-project.org/pipermail/development/2013-January/009284.html Change-Id: Id2bb2e2cabde059305d4af5f12593344ba30f001 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
* QVarLengthArray: add squeeze functionPeter Kümmel2013-01-281-0/+5
| | | | | | | Add function to move back data to the stack. Change-Id: Ic78a368459bce68629e29602e4eeae2e1afe398b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* QVarLengthArray: use memory on stack if possiblePeter Kümmel2012-10-111-5/+10
| | | | | | | | | | After allocating memory on the heap it is ATM not possible to use the memory on the stack again, QVarLengthArray then uses/resizes only the memory on the heap. But the memory on stack could be used if it is big enough. Change-Id: I566003c25dd1093eb6ba8087a1e5378a11712934 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QVarLengthArray exception safe in case of OOMPeter Kümmel2012-10-111-26/+22
| | | | | | | | | | | | | After a exception is thrown in resize(), QVarLengthArray has an invalid state with ptr == 0. On the next resize call when malloc returns a valid pointer, oldPtr is 0 and it could crash in memcpy because the pointer to the source is 0. The patch ensures the valid pointer isn't overwritten with NULL. When exceptions are disabled the user must ensure that malloc will not fail. Change-Id: Id12a5e3e1eacc551e4d1b64cba8e8414cfebd6e1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* QVarLengthArray: provide STL-compatible member function namesMarc Mutz2012-09-191-0/+9
| | | | | | | | | This allows, among other things, to use QVarLengthArray as the target of a std::back_insert_iterator. Change-Id: I507f612a23da854bf865780aa0a7e6312f4a896b Reviewed-by: João Abecasis <joao.abecasis@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>