Fixed clazy warnings: pass large objects by reference to const.

This commit is contained in:
Mat Sutcliffe
2018-12-17 16:43:54 +00:00
parent e40af8132c
commit 9f85a7b560
27 changed files with 49 additions and 47 deletions

View File

@@ -83,7 +83,7 @@ namespace BlackMisc
return this->getApplication() == Unknown && m_exePath.isNull();
}
QString CApplicationInfo::asOtherSwiftVersionString(const QString separator) const
QString CApplicationInfo::asOtherSwiftVersionString(const QString &separator) const
{
return QStringLiteral("Version; ") % this->getVersionString() % QStringLiteral(" os: ") % this->getPlatform() % separator %
QStringLiteral("exe.path: ") % this->getExecutablePath() % separator %

View File

@@ -129,7 +129,7 @@ namespace BlackMisc
bool isNull() const;
//! Formatted info
QString asOtherSwiftVersionString(const QString separator = " | ") const;
QString asOtherSwiftVersionString(const QString &separator = " | ") const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;

View File

@@ -110,13 +110,13 @@ namespace BlackMisc
return connection.name().contains(p2pConnectionName());
}
bool CDBusServer::dBusAddressToHostAndPort(QString address, QString &host, int &port)
bool CDBusServer::dBusAddressToHostAndPort(const QString &address, QString &host, int &port)
{
address = address.trimmed().toLower().replace(' ', "");
if (address.contains("host=") || address.contains("port="))
const QString canonicalAddress = address.trimmed().toLower().replace(' ', "");
if (canonicalAddress.contains("host=") || canonicalAddress.contains("port="))
{
// "tcp:host=foo.com,port=123"
const QStringList parts(address.split(','));
const QStringList parts(canonicalAddress.split(','));
for (const QString &part : parts)
{
// "host=" or "tcp:host="
@@ -145,7 +145,7 @@ namespace BlackMisc
}
}
bool CDBusServer::dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, QString &o_port)
bool CDBusServer::dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, QString &o_port)
{
int port;
const bool s = dBusAddressToHostAndPort(dbusAddress, o_host, port);

View File

@@ -126,10 +126,10 @@ namespace BlackMisc
static bool isP2PConnection(const QDBusConnection &connection);
//! Extract host and port from a DBus address
static bool dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, int &o_port);
static bool dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, int &o_port);
//! Extract host and port from a DBus address
static bool dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, QString &o_port);
static bool dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, QString &o_port);
//! Is the given connection one of the default connections?
static bool isQtDefaultConnection(const QDBusConnection &connection);

View File

@@ -82,7 +82,7 @@ namespace BlackMisc
return encryptToByteArray(plaintextArray);
}
QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
QByteArray SimpleCrypt::encryptToByteArray(const QByteArray &plaintext)
{
if (m_keyParts.isEmpty())
{
@@ -159,7 +159,7 @@ namespace BlackMisc
return cypherString;
}
QString SimpleCrypt::encryptToString(QByteArray plaintext)
QString SimpleCrypt::encryptToString(const QByteArray &plaintext)
{
QByteArray cypher = encryptToByteArray(plaintext);
QString cypherString = QString::fromLatin1(cypher.toBase64());
@@ -175,7 +175,7 @@ namespace BlackMisc
return plaintext;
}
QString SimpleCrypt::decryptToString(QByteArray cypher)
QString SimpleCrypt::decryptToString(const QByteArray &cypher)
{
QByteArray ba = decryptToByteArray(cypher);
QString plaintext = QString::fromUtf8(ba, ba.size());
@@ -191,7 +191,7 @@ namespace BlackMisc
return ba;
}
QByteArray SimpleCrypt::decryptToByteArray(QByteArray cypher)
QByteArray SimpleCrypt::decryptToByteArray(const QByteArray &cypher)
{
if (m_keyParts.isEmpty())
{

View File

@@ -147,7 +147,7 @@ namespace BlackMisc
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
actual result of the encryption, so it can be stored easily in a text format.
*/
QString encryptToString(QByteArray plaintext) ;
QString encryptToString(const QByteArray &plaintext) ;
/**
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
@@ -165,7 +165,7 @@ namespace BlackMisc
This method returns a byte array, that is useable for storing a binary format. If you need
a string you can store in a text file, use encryptToString() instead.
*/
QByteArray encryptToByteArray(QByteArray plaintext) ;
QByteArray encryptToByteArray(const QByteArray &plaintext) ;
/**
Decrypts a cyphertext string encrypted with this class with the set key back to the
@@ -192,7 +192,7 @@ namespace BlackMisc
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QString decryptToString(QByteArray cypher) ;
QString decryptToString(const QByteArray &cypher) ;
/**
Decrypts a cyphertext binary encrypted with this class with the set key back to the
@@ -201,7 +201,7 @@ namespace BlackMisc
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QByteArray decryptToByteArray(QByteArray cypher) ;
QByteArray decryptToByteArray(const QByteArray &cypher) ;
/**
Enum to describe options that have been used for the encryption. Currently only one, but

View File

@@ -608,7 +608,7 @@ namespace BlackMisc
struct CValuePage::Element
{
Element(const QString &key, const QString &name, int metaType, Validator validator, const CVariant &defaultValue) :
Element(const QString &key, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue) :
m_key(key), m_name(name), m_metaType(metaType), m_validator(validator), m_default(defaultValue)
{}
const QString m_key;
@@ -624,7 +624,7 @@ namespace BlackMisc
bool m_saved = false;
};
CValuePage::Element &CValuePage::createElement(const QString &keyTemplate, const QString &name, int metaType, Validator validator, const CVariant &defaultValue)
CValuePage::Element &CValuePage::createElement(const QString &keyTemplate, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue)
{
if (parent()->objectName().isEmpty() && keyTemplate.contains("%OwnerName%"))
{
@@ -667,7 +667,7 @@ namespace BlackMisc
return element;
}
void CValuePage::setNotifySlot(Element &element, NotifySlot slot)
void CValuePage::setNotifySlot(Element &element, const NotifySlot &slot)
{
element.m_notifySlot = slot;
}

View File

@@ -456,7 +456,7 @@ namespace BlackMisc
protected:
//! \private Connect a function to be called (only once) when the owner's objectName changes.
void onOwnerNameChanged(std::function<void()> function)
void onOwnerNameChanged(const std::function<void()> &function)
{
connectOnce(m_page->parent(), &QObject::objectNameChanged, [function](const QString &) { function(); });
}

View File

@@ -84,10 +84,10 @@ namespace BlackMisc
//! \param metaType The Qt metatype ID of the value object's expected type.
//! \param validator Optional functor which returns true if the value is valid.
//! \param defaultValue Optional value which is used in case the value is invalid.
Element &createElement(const QString &key, const QString &name, int metaType, Validator validator, const CVariant &defaultValue);
Element &createElement(const QString &key, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue);
//! Set the functor to call to notify that the value corresponding to the element's key was modified.
void setNotifySlot(Element &element, NotifySlot slot);
void setNotifySlot(Element &element, const NotifySlot &slot);
//! True if the currently paged value corresponds to a valid key.
bool isInitialized(const Element &element) const;

View File

@@ -59,7 +59,7 @@ namespace BlackMisc
Q_UNUSED(ok);
}
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task)
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, const std::function<CVariant()> &task)
{
auto *worker = new CWorker(task);
emit worker->aboutToStart();

View File

@@ -268,8 +268,8 @@ namespace BlackMisc
void ps_runTask();
private:
CWorker(std::function<CVariant()> task) : m_task(task) {}
static CWorker *fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task);
CWorker(const std::function<CVariant()> &task) : m_task(task) {}
static CWorker *fromTaskImpl(QObject *owner, const QString &name, int typeId, const std::function<CVariant()> &task);
template <typename R>
R resultNoWait() { Q_ASSERT(m_result.canConvert<R>()); return m_result.value<R>(); }