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>
bb10
Marc Mutz 2022-05-12 07:30:23 +02:00
parent 20d8383cb4
commit fd31177c45
2 changed files with 22 additions and 25 deletions

View File

@ -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')

View File

@ -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;