Reduce unnecessary copies using move semantics

This commit is contained in:
Gianluca Recchia 2018-10-28 16:13:58 +01:00
parent 896a66e6d8
commit 379c41d20c
No known key found for this signature in database
GPG Key ID: 3C2B4128D9A1F218
10 changed files with 24 additions and 13 deletions

View File

@ -18,12 +18,13 @@
#include "WildcardMatcher.h"
#include <QStringList>
#include <utility>
const QChar WildcardMatcher::Wildcard = '*';
const Qt::CaseSensitivity WildcardMatcher::Sensitivity = Qt::CaseInsensitive;
WildcardMatcher::WildcardMatcher(const QString& text)
: m_text(text)
WildcardMatcher::WildcardMatcher(QString text)
: m_text(std::move(text))
{
}

View File

@ -23,7 +23,7 @@
class WildcardMatcher
{
public:
explicit WildcardMatcher(const QString& text);
explicit WildcardMatcher(QString text);
bool match(const QString& pattern);
static const QChar Wildcard;

View File

@ -18,6 +18,8 @@
#include "AutoTypeMatch.h"
#include <utility>
AutoTypeMatch::AutoTypeMatch()
: entry(nullptr)
, sequence()
@ -26,7 +28,7 @@ AutoTypeMatch::AutoTypeMatch()
AutoTypeMatch::AutoTypeMatch(Entry* entry, QString sequence)
: entry(entry)
, sequence(sequence)
, sequence(std::move(sequence))
{
}

View File

@ -25,6 +25,7 @@
#include <QTextStream>
#include <QTimer>
#include <QXmlStreamReader>
#include <utility>
#include "cli/Utils.h"
#include "core/Clock.h"
@ -492,7 +493,7 @@ Database* Database::openDatabaseFile(const QString& fileName, QSharedPointer<con
}
KeePass2Reader reader;
Database* db = reader.readDatabase(&dbFile, key);
Database* db = reader.readDatabase(&dbFile, std::move(key));
if (reader.hasError()) {
qCritical("Error while parsing the database: %s", qPrintable(reader.errorString()));
return nullptr;

View File

@ -29,6 +29,7 @@
#include <QDebug>
#include <QDir>
#include <QRegularExpression>
#include <utility>
const int Entry::DefaultIconNumber = 0;
const int Entry::ResolveMaximumDepth = 10;
@ -367,7 +368,7 @@ QString Entry::totp() const
void Entry::setTotp(QSharedPointer<Totp::Settings> settings)
{
beginUpdate();
m_data.totpSettings = settings;
m_data.totpSettings = std::move(settings);
auto text = Totp::writeSettings(m_data.totpSettings, title(), username());
if (m_attributes->hasKey(Totp::ATTRIBUTE_OTP)) {

View File

@ -28,6 +28,7 @@
#include <QBuffer>
#include <QFile>
#include <utility>
#define UUID_LENGTH 16
@ -43,9 +44,9 @@ KdbxXmlReader::KdbxXmlReader(quint32 version)
* @param version KDBX version
* @param binaryPool binary pool
*/
KdbxXmlReader::KdbxXmlReader(quint32 version, const QHash<QString, QByteArray>& binaryPool)
KdbxXmlReader::KdbxXmlReader(quint32 version, QHash<QString, QByteArray> binaryPool)
: m_kdbxVersion(version)
, m_binaryPool(binaryPool)
, m_binaryPool(std::move(binaryPool))
{
}

View File

@ -42,7 +42,7 @@ class KdbxXmlReader
public:
explicit KdbxXmlReader(quint32 version);
explicit KdbxXmlReader(quint32 version, const QHash<QString, QByteArray>& binaryPool);
explicit KdbxXmlReader(quint32 version, QHash<QString, QByteArray> binaryPool);
virtual ~KdbxXmlReader() = default;
virtual Database* readDatabase(const QString& filename);

View File

@ -21,6 +21,7 @@
#include "format/KeePass1.h"
#include <QFile>
#include <utility>
/**
* Read database from file and detect correct file format.
@ -37,7 +38,7 @@ Database* KeePass2Reader::readDatabase(const QString& filename, QSharedPointer<c
return nullptr;
}
QScopedPointer<Database> db(readDatabase(&file, key));
QScopedPointer<Database> db(readDatabase(&file, std::move(key)));
if (file.error() != QFile::NoError) {
raiseError(file.errorString());

View File

@ -18,6 +18,8 @@
#include "CsvParserModel.h"
#include <utility>
CsvParserModel::CsvParserModel(QObject* parent)
: QAbstractTableModel(parent)
, m_skipped(0)
@ -92,7 +94,7 @@ void CsvParserModel::setSkippedRows(int skipped)
void CsvParserModel::setHeaderLabels(QStringList l)
{
m_columnHeader = l;
m_columnHeader = std::move(l);
}
int CsvParserModel::rowCount(const QModelIndex& parent) const

View File

@ -17,6 +17,8 @@
#include "HmacBlockStream.h"
#include <utility>
#include "core/Endian.h"
#include "crypto/CryptoHash.h"
@ -25,7 +27,7 @@ const QSysInfo::Endian HmacBlockStream::ByteOrder = QSysInfo::LittleEndian;
HmacBlockStream::HmacBlockStream(QIODevice* baseDevice, QByteArray key)
: LayeredStream(baseDevice)
, m_blockSize(1024 * 1024)
, m_key(key)
, m_key(std::move(key))
{
init();
}
@ -33,7 +35,7 @@ HmacBlockStream::HmacBlockStream(QIODevice* baseDevice, QByteArray key)
HmacBlockStream::HmacBlockStream(QIODevice* baseDevice, QByteArray key, qint32 blockSize)
: LayeredStream(baseDevice)
, m_blockSize(blockSize)
, m_key(key)
, m_key(std::move(key))
{
init();
}