Pass QVariants by reference when possible

This commit is contained in:
Aleix Pol 2021-10-19 04:11:32 +02:00
parent 9135ad06ea
commit c8c193690a
2 changed files with 6 additions and 7 deletions

View file

@ -43,7 +43,7 @@ DBusResponseWaiter::DBusResponseWaiter()
; ;
} }
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const QVariant DBusResponseWaiter::waitForReply(const QVariant &variant) const
{ {
if (QDBusPendingCall* call = extractPendingCall(variant)) if (QDBusPendingCall* call = extractPendingCall(variant))
{ {
@ -74,8 +74,7 @@ DBusAsyncResponse::DBusAsyncResponse(QObject* parent)
connect(&m_timeout, &QTimer::timeout, this, &DBusAsyncResponse::onTimeout); connect(&m_timeout, &QTimer::timeout, this, &DBusAsyncResponse::onTimeout);
} }
void DBusAsyncResponse::setPendingCall(const QVariant &variant)
void DBusAsyncResponse::setPendingCall(QVariant variant)
{ {
if (QDBusPendingCall* call = DBusResponseWaiter::instance()->extractPendingCall(variant)) if (QDBusPendingCall* call = DBusResponseWaiter::instance()->extractPendingCall(variant))
{ {
@ -124,7 +123,7 @@ void DBusAsyncResponse::onTimeout()
Q_EMIT error(QStringLiteral("timeout when waiting dbus response!")); Q_EMIT error(QStringLiteral("timeout when waiting dbus response!"));
} }
QDBusPendingCall* DBusResponseWaiter::extractPendingCall(QVariant& variant) const QDBusPendingCall* DBusResponseWaiter::extractPendingCall(const QVariant& variant) const
{ {
for (int type : qAsConst(m_registered)) for (int type : qAsConst(m_registered))
{ {

View file

@ -23,9 +23,9 @@ public:
static DBusResponseWaiter* instance(); static DBusResponseWaiter* instance();
///extract QDbusPendingCall from \p variant and blocks until completed ///extract QDbusPendingCall from \p variant and blocks until completed
Q_INVOKABLE QVariant waitForReply(QVariant variant) const; Q_INVOKABLE QVariant waitForReply(const QVariant &variant) const;
QDBusPendingCall* extractPendingCall(QVariant& variant) const; QDBusPendingCall* extractPendingCall(const QVariant& variant) const;
private: private:
DBusResponseWaiter(); DBusResponseWaiter();
@ -44,7 +44,7 @@ public:
explicit DBusAsyncResponse(QObject* parent = nullptr); explicit DBusAsyncResponse(QObject* parent = nullptr);
~DBusAsyncResponse() override = default; ~DBusAsyncResponse() override = default;
Q_INVOKABLE void setPendingCall(QVariant e); Q_INVOKABLE void setPendingCall(const QVariant &e);
void setAutodelete(bool b) {m_autodelete = b;}; void setAutodelete(bool b) {m_autodelete = b;};
bool autodelete() const {return m_autodelete;} bool autodelete() const {return m_autodelete;}