summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-02 16:31:01 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-02-03 22:12:06 +0000
commit1e62f089985f0377c72f922d267839ce6f46c3cd (patch)
tree1dbd8d9c84301a8939da37505ee33317c165170c /src/corelib/io
parentbb9be221339b67b7580e92efc673f8919f4b1db8 (diff)
QBuffer: exterminate three thread-safe static guard variables
Instead of duplicating two dynamically-initialized statics each in two functions, causing four threading guards to be emitted by the compiler, pack the two variables into a static struct and the struct into an Extracted Method, leaving just a single threading guard. https://godbolt.org/z/a9e5o848f Uses C++14 NSDMI-in-aggregates, so doesn't work in 5.15. Pick-to: 6.3 6.2 Change-Id: I98e053df48aafd5720ceffd514d6811fd3b28b1a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qbuffer.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index 595fcd2724..a7da9ae600 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -444,15 +444,22 @@ qint64 QBuffer::writeData(const char *data, qint64 len)
}
#ifndef QT_NO_QOBJECT
+static bool is_tracked_signal(const QMetaMethod &signal)
+{
+ // dynamic initialization: minimize the number of guard variables:
+ static const struct {
+ QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);
+ QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);
+ } sigs;
+ return signal == sigs.readyReadSignal || signal == sigs.bytesWrittenSignal;
+}
/*!
\reimp
\internal
*/
void QBuffer::connectNotify(const QMetaMethod &signal)
{
- static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);
- static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);
- if (signal == readyReadSignal || signal == bytesWrittenSignal)
+ if (is_tracked_signal(signal))
d_func()->signalConnectionCount++;
}
@@ -463,9 +470,7 @@ void QBuffer::connectNotify(const QMetaMethod &signal)
void QBuffer::disconnectNotify(const QMetaMethod &signal)
{
if (signal.isValid()) {
- static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);
- static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);
- if (signal == readyReadSignal || signal == bytesWrittenSignal)
+ if (is_tracked_signal(signal))
d_func()->signalConnectionCount--;
} else {
d_func()->signalConnectionCount = 0;