diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-05-12 07:30:23 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-05-17 18:49:31 +0200 |
commit | fd31177c45fa47bab867503d8b1b1505ee81654e (patch) | |
tree | 58de6a0406eb6fe97ade3601c646f61c93d681ff /src | |
parent | 20d8383cb4899fb4c8d13c55ac19a718d1306cae (diff) |
QObject: Turn flaggedSignatures into a thread_local static
... out of QThreadData.
No-one except two functions in qobject.cpp uses the object, and its
creation is constinit, so there's no advantage to expose it to the
world as a QThreadData member.
Remove it from QThreadData, move the class' definition to the unnamed
namespace in qobject.cpp, ensure constinit'ability by letting the
language zero out the members (as opposed to an STL algorithm call),
declare it constinit thread_local static, and adapt the two users
(basically, removing the retrieval of QThreadData::current()).
Almost no effect on Clang, but saves ~400 bytes on optimized GCC 11.2
Linux AMD64 C++20 builds.
Change-Id: I22432d4ec5eb4ab59920656409b21768983fb4db
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 26 | ||||
-rw-r--r-- | src/corelib/thread/qthread_p.h | 21 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index ee168dfc79..c72b8a761c 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2602,11 +2602,29 @@ void QObject::deleteLater() Signals and slots *****************************************************************************/ +namespace { +// This class provides (per-thread) storage for qFlagLocation() +class FlaggedDebugSignatures +{ + static constexpr uint Count = 2; + + uint idx = 0; + const char *locations[Count] = {}; + +public: + void store(const char* method) + { locations[idx++ % Count] = method; } + + bool contains(const char *method) const + { return std::find(locations, locations + Count, method) != locations + Count; } +}; + +Q_THREAD_LOCAL_CONSTINIT static thread_local FlaggedDebugSignatures flaggedSignatures = {}; +} // unnamed namespace + const char *qFlagLocation(const char *method) { - QThreadData *currentThreadData = QThreadData::current(false); - if (currentThreadData != nullptr) - currentThreadData->flaggedSignatures.store(method); + flaggedSignatures.store(method); return method; } @@ -2618,7 +2636,7 @@ static int extract_code(const char *member) static const char *extract_location(const char *member) { - if (QThreadData::current()->flaggedSignatures.contains(member)) { + if (flaggedSignatures.contains(member)) { // signature includes location information after the first null-terminator const char *location = member + qstrlen(member) + 1; if (*location != '\0') diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 134c1577b2..6fdf785633 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -261,26 +261,6 @@ public: return canWait; } - // This class provides per-thread (by way of being a QThreadData - // member) storage for qFlagLocation() - class FlaggedDebugSignatures - { - static const uint Count = 2; - - uint idx; - const char *locations[Count]; - - public: - FlaggedDebugSignatures() : idx(0) - { std::fill_n(locations, Count, static_cast<char*>(nullptr)); } - - void store(const char* method) - { locations[idx++ % Count] = method; } - - bool contains(const char *method) const - { return std::find(locations, locations + Count, method) != locations + Count; } - }; - private: QAtomicInt _ref; @@ -294,7 +274,6 @@ public: QAtomicPointer<void> threadId; QAtomicPointer<QAbstractEventDispatcher> eventDispatcher; QList<void *> tls; - FlaggedDebugSignatures flaggedSignatures; bool quitNow; bool canWait; |