Skip to content

Commit

Permalink
make sure to pass shared pointer by const ref when possible
Browse files Browse the repository at this point in the history
avoid unnecessary copies of shared pointers

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Jun 30, 2023
1 parent 2d7158d commit 2ced4b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ void ClientSideEncryption::generateKeyPair(const AccountPtr &account)
});
}

std::pair<QByteArray, ClientSideEncryption::PKey> ClientSideEncryption::generateCSR(AccountPtr account,
std::pair<QByteArray, ClientSideEncryption::PKey> ClientSideEncryption::generateCSR(const AccountPtr &account,
PKey keyPair,
PKey privateKey)
{
Expand Down Expand Up @@ -1416,7 +1416,7 @@ std::pair<QByteArray, ClientSideEncryption::PKey> ClientSideEncryption::generate
return {result, std::move(keyPair)};
}

void ClientSideEncryption::sendSignRequestCSR(AccountPtr account,
void ClientSideEncryption::sendSignRequestCSR(const AccountPtr &account,
PKey keyPair,
QByteArray csrContent)
{
Expand Down Expand Up @@ -1452,7 +1452,7 @@ void ClientSideEncryption::sendSignRequestCSR(AccountPtr account,
job->start();
}

void ClientSideEncryption::writeKeyPair(AccountPtr account,
void ClientSideEncryption::writeKeyPair(const AccountPtr &account,
PKey keyPair,
QByteArray output)
{
Expand Down Expand Up @@ -1516,7 +1516,7 @@ void ClientSideEncryption::writeKeyPair(AccountPtr account,
privateKeyJob->start();
}

void ClientSideEncryption::checkServerHasSavedKeys(AccountPtr account)
void ClientSideEncryption::checkServerHasSavedKeys(const AccountPtr &account)
{
const auto keyIsNotOnServer = [account, this] () {
qCInfo(lcCse) << "server is missing keys. deleting local keys";
Expand All @@ -1537,7 +1537,7 @@ void ClientSideEncryption::checkServerHasSavedKeys(AccountPtr account)

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void ClientSideEncryption::checkUserKeyOnServer(const QString &keyType,
OCC::AccountPtr account,
const AccountPtr &account,
SUCCESS_CALLBACK nextCheck,
ERROR_CALLBACK onError)
{
Expand All @@ -1556,15 +1556,15 @@ void ClientSideEncryption::checkUserKeyOnServer(const QString &keyType,
}

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void ClientSideEncryption::checkUserPublicKeyOnServer(AccountPtr account,
void ClientSideEncryption::checkUserPublicKeyOnServer(const AccountPtr &account,
SUCCESS_CALLBACK nextCheck,
ERROR_CALLBACK onError)
{
checkUserKeyOnServer("public-key", account, nextCheck, onError);
}

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void ClientSideEncryption::checkUserPrivateKeyOnServer(AccountPtr account, SUCCESS_CALLBACK nextCheck, ERROR_CALLBACK onError)
void ClientSideEncryption::checkUserPrivateKeyOnServer(const AccountPtr &account, SUCCESS_CALLBACK nextCheck, ERROR_CALLBACK onError)
{
checkUserKeyOnServer("private-key", account, nextCheck, onError);
}
Expand Down Expand Up @@ -1759,7 +1759,7 @@ FolderMetadata::FolderMetadata(AccountPtr account,
RequiredMetadataVersion requiredMetadataVersion,
const QByteArray& metadata,
int statusCode)
: _account(account)
: _account(std::move(account))
, _requiredMetadataVersion(requiredMetadataVersion)
{
if (metadata.isEmpty() || statusCode == 404) {
Expand Down
14 changes: 7 additions & 7 deletions src/libsync/clientsideencryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,37 +169,37 @@ private slots:
private:
void generateMnemonic();

[[nodiscard]] std::pair<QByteArray, PKey> generateCSR(AccountPtr account,
[[nodiscard]] std::pair<QByteArray, PKey> generateCSR(const AccountPtr &account,
PKey keyPair,
PKey privateKey);

void sendSignRequestCSR(AccountPtr account,
void sendSignRequestCSR(const AccountPtr &account,
PKey keyPair,
QByteArray csrContent);

void writeKeyPair(AccountPtr account,
void writeKeyPair(const AccountPtr &account,
PKey keyPair,
QByteArray output);

template <typename L>
void writeMnemonic(OCC::AccountPtr account,
L nextCall);

void checkServerHasSavedKeys(AccountPtr account);
void checkServerHasSavedKeys(const AccountPtr &account);

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void checkUserPublicKeyOnServer(OCC::AccountPtr account,
void checkUserPublicKeyOnServer(const OCC::AccountPtr &account,
SUCCESS_CALLBACK nextCheck,
ERROR_CALLBACK onError);

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void checkUserPrivateKeyOnServer(OCC::AccountPtr account,
void checkUserPrivateKeyOnServer(const OCC::AccountPtr &account,
SUCCESS_CALLBACK nextCheck,
ERROR_CALLBACK onError);

template <typename SUCCESS_CALLBACK, typename ERROR_CALLBACK>
void checkUserKeyOnServer(const QString &keyType,
OCC::AccountPtr account,
const OCC::AccountPtr &account,
SUCCESS_CALLBACK nextCheck,
ERROR_CALLBACK onError);

Expand Down

0 comments on commit 2ced4b6

Please sign in to comment.