summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qtaggedpointer.h
Commit message (Collapse)AuthorAgeFilesLines
* Mark all remaining RAII/smart pointer class ctors [[nodiscard]]Marc Mutz2023-06-221-3/+3
| | | | | | | | | | | | | | | | | | | ... like QUIP-0019 suggests. The main problem here is finding these classes. We don't have markup for RAII classes, so I had to find them by name. This patch is based on the output of git grep -we Q[A-Z0-9a-z_]+er extracting the matches and piping them through sort -u, then removing a lot of suffixes like Manager and Handler, then visually inspecting the remaining list. Task-number: QTBUG-104164 Pick-to: 6.6 Change-Id: I59b18d8d0a0237fcc11047857adc39b984ad7fcb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QTaggedPointer: fix warning due to integer type conversionHamish Moffatt2023-03-271-1/+1
| | | | | | | | Fixes: QTBUG-112222 Pick-to: 6.5 Change-Id: I4815d83c23e7616548ea84779d1c3d0774e77f69 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTaggedPointer: Assert on the same tag value as we use in setTag()Ulf Hermann2022-11-301-2/+4
| | | | | | | | | | If we assert on a different cast we may just get a different integer value, if Tag is a sufficiently nefarious type. Coverity-Id: 403056 Change-Id: I6e8e3883bce124b3350ad8276d88ac7ed030d982 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTaggedPointer: disable operator= with an empty initializer listGiuseppe D'Angelo2022-09-291-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given a QTaggedPointer, users may write taggedPtr = {}; to mean "reset it". This is error-prone: due to overload resolution, this actually ends up calling QTaggedPointer<T>::operator=(T *), which changes the pointer but *not* the tag, and not the implicitly declared QTaggedPointer<T>:operator=(const QTaggedPointer<T> &) which would reset both pointer and tag. Given the idiomatic usage of {} is indeed to perform a full reset (cf. std::exchange(obj, {}), std::take, etc.), work around this by disabling the operator= overload for pointers in case an initializer list is passed. In other words, make `={}` fall back to the implicitly declared overload. Note, this breaks some usages, such as taggedPtr = {rawPtr}; but at least we get a compile error for these, and they don't look common at all. [ChangeLog][QtCore][QTaggedPointer] The operator assignment taking a raw pointer has been reimplemented in order to avoid subtle issues when assigning `{}` to a QTaggedPointer. This will cause code that assigns a braced-init-list to a QTaggedPointer object to stop compiling (for instance, `tagPtr = {ptr}` is now ill-formed). Change-Id: I5e572a9b0f119ddb2df17f1797934933dff2ba7b Task-number: QTBUG-106070 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add a few explicit conversions back from intThiago Macieira2022-01-121-1/+1
| | | | | | | | | | Suppresses GCC's -Wconversion, which is not enabled by default. error: conversion from ‘int’ to ‘quint8’ {aka ‘unsigned char’} may change value [-Werror=conversion] Change-Id: I0e5f6bec596a4a78bd3bfffd16c998102bd51f7c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Optimize code in QTaggedPointerLars Knoll2020-11-301-6/+5
| | | | | | | | | | | | | | | Don't execute instructions that will never do anything. Directly add the tag to the pointer in the constructor to avoid additional masking operations, and avoid a masking op that is in practice a no-op in setTag(). Do the same optimization in QTagPreservingPointerToPointer. Change-Id: Ia364f89cbe6ccc876ec9bda0c239fc4f57c10501 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 2721728c9056b442c0281f20792f19eb6a491aa0) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-1/+1
| | | | | | | | | | | | | | | | | 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>
* QTaggedPointer: some API cleanupsMarc Mutz2020-05-151-25/+25
| | | | | | | | | | | | | | | | | - don't refer to the class with template arguments in the body of the class (incl. one where we got the template args wrong) - make namespace-level swap a non-member friend - make default ctor constexpr and non-explicit (default ctors should never be explicit) - make ctor from std::nullptr_t constexpr - remove op= from std::nullptr (will be handled by op=(T*) anyway) - pass QTaggedPointer by value (it's a Trivial Type, so can be passed in registers) - fix missing QTypeInfo for non-default Tag types - remove unused include limits.h - make qHash-able (why is the tag ignored?) Change-Id: Idee1d685ac365c988698a8637fd5df3accfc1396 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change QTaggedPointer API to be more similar to other smart pointers in QtSimon Hausmann2020-03-191-8/+8
| | | | | | | * Rename pointer() to data() Change-Id: I8ef3e552d45c9990fee4b7efa98e2d878ed2cf98 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Add documentation for QTaggedPointerSimon Hausmann2020-03-191-8/+8
| | | | | | | | The class remains \internal though, as it has a very narrow use-case for low-level code inside Qt. Change-Id: I9d2b6486ce29b290af7f930a0bfc78590a83cc01 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Use QTaggedPointer in QPropertyObserverSimon Hausmann2020-03-191-3/+3
| | | | | | | | | | This replaces the private tagged pointer and the use of enums for the tag makes the observer handling code more readable. The pointer-to-tagged-pointer class remains in qpropertyprivate.h due to its exoticness. Change-Id: Icc88799136c6839426d994b42368526463265e66 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make it possible to use QTaggedPointer within classesSimon Hausmann2020-03-171-12/+10
| | | | | | | | | | | | | | A common pattern in declarative is to use the unused bits in linked list next pointers for additional information storage. The "next" pointer is typically then a tagged pointer of the containing class, which is not fully defined yet. Therefore alignof() can't be used at tagged pointer instantiation time. This patch delays the calls to alignment, etc. until the corresponding functions are used, as in principle the tagged pointer is just a quintptr and no additional information should be needed until operating on it. Change-Id: I87a3578ee921d471e1b60ed5903b549ef0610b97 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Introduce helper class QTaggedPointerTor Arne Vestbø2020-03-171-0/+207
Useful for attaching small bits of information in the alignment bits of a naked pointer. For use in the new property system as well as in qtdeclarative (where currently a similar class exists as private API). Change-Id: Idf9b93e714e15129f302e16425dbeda94bcd207b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>