Skip to content

Commit

Permalink
Reduce unnecessary copies using move semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianluca Recchia committed Oct 31, 2018
1 parent 896a66e commit 379c41d
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/autotype/WildcardMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/autotype/WildcardMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/core/AutoTypeMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "AutoTypeMatch.h"

#include <utility>

AutoTypeMatch::AutoTypeMatch()
: entry(nullptr)
, sequence()
Expand All @@ -26,7 +28,7 @@ AutoTypeMatch::AutoTypeMatch()

AutoTypeMatch::AutoTypeMatch(Entry* entry, QString sequence)
: entry(entry)
, sequence(sequence)
, sequence(std::move(sequence))
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QTextStream>
#include <QTimer>
#include <QXmlStreamReader>
#include <utility>

#include "cli/Utils.h"
#include "core/Clock.h"
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QDebug>
#include <QDir>
#include <QRegularExpression>
#include <utility>

const int Entry::DefaultIconNumber = 0;
const int Entry::ResolveMaximumDepth = 10;
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 3 additions & 2 deletions src/format/KdbxXmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <QBuffer>
#include <QFile>
#include <utility>

#define UUID_LENGTH 16

Expand All @@ -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))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/format/KdbxXmlReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/format/KeePass2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "format/KeePass1.h"

#include <QFile>
#include <utility>

/**
* Read database from file and detect correct file format.
Expand All @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/gui/csvImport/CsvParserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "CsvParserModel.h"

#include <utility>

CsvParserModel::CsvParserModel(QObject* parent)
: QAbstractTableModel(parent)
, m_skipped(0)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/streams/HmacBlockStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "HmacBlockStream.h"

#include <utility>

#include "core/Endian.h"
#include "crypto/CryptoHash.h"

Expand All @@ -25,15 +27,15 @@ 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();
}

HmacBlockStream::HmacBlockStream(QIODevice* baseDevice, QByteArray key, qint32 blockSize)
: LayeredStream(baseDevice)
, m_blockSize(blockSize)
, m_key(key)
, m_key(std::move(key))
{
init();
}
Expand Down

0 comments on commit 379c41d

Please sign in to comment.