From 34fe9232dbf6a9fe58ebc4c7680bb67d2f642c40 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 10 Jun 2019 11:08:29 +0200 Subject: Port from QAtomic::load() to loadRelaxed() Semi-automated, just needed ~20 manual fixes: $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)load\(\)/$1loadRelaxed\(\)/g' -i \{\} + $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)store\(/$1storeRelaxed\(/g' -i \{\} + It can be easily improved (e.g. for store check that there are no commas after the opening parens). The most common offender is QLibrary::load, and some code using std::atomic directly. Change-Id: I07c38a3c8ed32c924ef4999e85c7e45cf48f0f6c Reviewed-by: Marc Mutz --- src/dbus/qdbusintegrator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/dbus/qdbusintegrator.cpp') diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 640acc2425..af16940d4f 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -534,7 +534,7 @@ qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data) bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) { - if (!ref.load()) + if (!ref.loadRelaxed()) return false; // local message are always delivered, regardless of filtering @@ -1077,7 +1077,7 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate() if (lastMode == ClientMode || lastMode == PeerMode) { // the bus service object holds a reference back to us; // we need to destroy it before we finish destroying ourselves - Q_ASSERT(ref.load() == 0); + Q_ASSERT(ref.loadRelaxed() == 0); QObject *obj = (QObject *)busService; if (obj) { disconnect(obj, nullptr, this, nullptr); @@ -2126,11 +2126,11 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM if ((receiver && returnMethod) || errorMethod) { // no one waiting, will delete pcall in processFinishedCall() - pcall->ref.store(1); + pcall->ref.storeRelaxed(1); } else { // set double ref to prevent race between processFinishedCall() and ref counting // by QDBusPendingCall::QExplicitlySharedDataPointer - pcall->ref.store(2); + pcall->ref.storeRelaxed(2); } if (isLoopback) { -- cgit v1.2.3 From f8f4a75d82b0fdf7cd19ba241c6ea406e7442d22 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 3 Jun 2019 23:08:05 +0200 Subject: QtDBus: use new QLatin1String::arg() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saves more than 4KiB in text size (~0.7%) on optimized GCC 9.1 Linux AMD64 builds. Change-Id: I5b29eae620370abd91e3a7f98e660c32470aed1c Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- src/dbus/qdbusintegrator.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/dbus/qdbusintegrator.cpp') diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index af16940d4f..9306498f89 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -340,8 +340,9 @@ static QByteArray buildMatchRule(const QString &service, const QString &objectPath, const QString &interface, const QString &member, const QDBusConnectionPrivate::ArgMatchRules &argMatch, const QString & /*signature*/) { - QString result = QLatin1String("type='signal',"); - QString keyValue = QLatin1String("%1='%2',"); + QString result; + result += QLatin1String("type='signal',"); + const auto keyValue = QLatin1String("%1='%2',"); if (!service.isEmpty()) result += keyValue.arg(QLatin1String("sender"), service); @@ -354,13 +355,13 @@ static QByteArray buildMatchRule(const QString &service, // add the argument string-matching now if (!argMatch.args.isEmpty()) { - keyValue = QLatin1String("arg%1='%2',"); + const QString keyValue = QLatin1String("arg%1='%2',"); for (int i = 0; i < argMatch.args.count(); ++i) if (!argMatch.args.at(i).isNull()) result += keyValue.arg(i).arg(argMatch.args.at(i)); } if (!argMatch.arg0namespace.isEmpty()) { - result += QStringLiteral("arg0namespace='%1',").arg(argMatch.arg0namespace); + result += QLatin1String("arg0namespace='%1',").arg(argMatch.arg0namespace); } result.chop(1); // remove ending comma @@ -1369,19 +1370,19 @@ void QDBusConnectionPrivate::sendError(const QDBusMessage &msg, QDBusError::Erro if (msg.interface().isEmpty()) interfaceMsg = QLatin1String("any interface"); else - interfaceMsg = QString::fromLatin1("interface '%1'").arg(msg.interface()); + interfaceMsg = QLatin1String("interface '%1'").arg(msg.interface()); send(msg.createErrorReply(code, - QString::fromLatin1("No such method '%1' in %2 at object path '%3' " - "(signature '%4')") + QLatin1String("No such method '%1' in %2 at object path '%3' " + "(signature '%4')") .arg(msg.member(), interfaceMsg, msg.path(), msg.signature()))); } else if (code == QDBusError::UnknownInterface) { send(msg.createErrorReply(QDBusError::UnknownInterface, - QString::fromLatin1("No such interface '%1' at object path '%2'") + QLatin1String("No such interface '%1' at object path '%2'") .arg(msg.interface(), msg.path()))); } else if (code == QDBusError::UnknownObject) { send(msg.createErrorReply(QDBusError::UnknownObject, - QString::fromLatin1("No such object path '%1'").arg(msg.path()))); + QLatin1String("No such object path '%1'").arg(msg.path()))); } } @@ -1551,8 +1552,8 @@ void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg) objThread = result.obj->thread(); if (!objThread) { send(msg.createErrorReply(QDBusError::InternalError, - QString::fromLatin1("Object '%1' (at path '%2')" - " has no thread. Cannot deliver message.") + QLatin1String("Object '%1' (at path '%2')" + " has no thread. Cannot deliver message.") .arg(result.obj->objectName(), msg.path()))); return; } @@ -2082,7 +2083,7 @@ QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal(const QDBusMessage &mess if (interface.isEmpty()) interface = QLatin1String(""); return QDBusMessage::createError(QDBusError::InternalError, - QString::fromLatin1("Internal error trying to call %1.%2 at %3 (signature '%4'") + QLatin1String("Internal error trying to call %1.%2 at %3 (signature '%4'") .arg(interface, message.member(), message.path(), message.signature())); } -- cgit v1.2.3