Commit 85079339 authored by Filip Gawin's avatar Filip Gawin
Browse files

Avoid copying if it's possible

(Can be meaningful if memory is dynamically allocated.)
parent 748f181a
......@@ -95,7 +95,7 @@ const KateFileTreePluginSettings &KateFileTreePlugin::settings()
return m_settings;
}
void KateFileTreePlugin::applyConfig(bool shadingEnabled, QColor viewShade, QColor editShade, bool listMode, int sortRole, bool showFullPath)
void KateFileTreePlugin::applyConfig(bool shadingEnabled, const QColor& viewShade, const QColor& editShade, bool listMode, int sortRole, bool showFullPath)
{
// save to settings
m_settings.setShadingEnabled(shadingEnabled);
......
......@@ -56,7 +56,7 @@ public:
const KateFileTreePluginSettings &settings();
void applyConfig(bool shadingEnabled, QColor viewShade, QColor editShade, bool listMode, int sortRole, bool showFulPath);
void applyConfig(bool shadingEnabled, const QColor& viewShade, const QColor& editShade, bool listMode, int sortRole, bool showFulPath);
public Q_SLOTS:
void viewDestroyed(QObject *view);
......
......@@ -278,7 +278,7 @@ void KateBuildView::readSessionConfig(const KConfigGroup& cg)
}
else {
for (int tn=0; tn<targetNames.size(); ++tn) {
const QString targetName = targetNames.at(tn);
const QString& targetName = targetNames.at(tn);
m_targetsUi->targetsModel.addCommand(i, targetName, cg.readEntry(QStringLiteral("%1 BuildCmd %2").arg(i).arg(targetName), DefBuildCmd));
}
QString defCmd = cg.readEntry(QStringLiteral("%1 Target Default").arg(i), QString());
......
......@@ -35,6 +35,7 @@
#include <QUrl>
#include <algorithm>
#include <utility>
#define RETURN_CACHED_ICON(name) \
{ \
......@@ -139,7 +140,7 @@ struct LSPClientCompletionItem : public LSPCompletionItem {
}
};
static bool compare_match(const LSPCompletionItem &a, const LSPCompletionItem b)
static bool compare_match(const LSPCompletionItem &a, const LSPCompletionItem& b)
{
return a.sortText < b.sortText;
}
......@@ -163,7 +164,7 @@ class LSPClientCompletionImpl : public LSPClientCompletion
public:
LSPClientCompletionImpl(QSharedPointer<LSPClientServerManager> manager)
: LSPClientCompletion(nullptr), m_manager(manager), m_server(nullptr)
: LSPClientCompletion(nullptr), m_manager(std::move(manager)), m_server(nullptr)
{
}
......@@ -330,7 +331,7 @@ public:
LSPClientCompletion *LSPClientCompletion::new_(QSharedPointer<LSPClientServerManager> manager)
{
return new LSPClientCompletionImpl(manager);
return new LSPClientCompletionImpl(std::move(manager));
}
#include "lspclientcompletion.moc"
......@@ -33,6 +33,7 @@
#include <KTextEditor/View>
#include <QToolTip>
#include <utility>
class LSPClientHoverImpl : public LSPClientHover
{
......@@ -47,7 +48,7 @@ class LSPClientHoverImpl : public LSPClientHover
public:
LSPClientHoverImpl(QSharedPointer<LSPClientServerManager> manager)
: LSPClientHover(), m_manager(manager), m_server(nullptr)
: LSPClientHover(), m_manager(std::move(manager)), m_server(nullptr)
{
}
......@@ -112,7 +113,7 @@ public:
LSPClientHover*
LSPClientHover::new_(QSharedPointer<LSPClientServerManager> manager)
{
return new LSPClientHoverImpl(manager);
return new LSPClientHoverImpl(std::move(manager));
}
#include "lspclienthover.moc"
......@@ -64,6 +64,7 @@
#include <QApplication>
#include <QFileInfo>
#include <QJsonObject>
#include <utility>
namespace RangeData {
......@@ -277,7 +278,7 @@ public:
m_plugin(plugin),
m_mainWindow(mainWin),
m_client(client),
m_serverManager(serverManager),
m_serverManager(std::move(serverManager)),
m_completion(LSPClientCompletion::new_(m_serverManager)),
m_hover(LSPClientHover::new_(m_serverManager)),
m_symbolView(LSPClientSymbolView::new_(plugin, mainWin, m_serverManager))
......@@ -737,7 +738,7 @@ public:
DiagnosticItem(const LSPDiagnostic &d) : m_diagnostic(d) {}
DiagnosticItem(const LSPCodeAction &c, QSharedPointer<LSPClientRevisionSnapshot> s)
: m_codeAction(c), m_snapshot(s)
: m_codeAction(c), m_snapshot(std::move(s))
{
m_diagnostic.range = LSPRange::invalid();
}
......@@ -788,7 +789,7 @@ public:
QPersistentModelIndex pindex(index);
QSharedPointer<LSPClientRevisionSnapshot> snapshot(
m_serverManager->snapshot(server.data()));
auto h = [this, url, snapshot, pindex](const QList<LSPCodeAction> actions) {
auto h = [this, url, snapshot, pindex](const QList<LSPCodeAction>& actions) {
if (!pindex.isValid())
return;
auto child = m_diagnosticsModel->itemFromIndex(pindex);
......
......@@ -36,6 +36,7 @@
#include <QCoreApplication>
#include <QTime>
#include <QFileInfo>
#include <utility>
// good/bad old school; allows easier concatenate
#define CONTENT_LENGTH "Content-Length"
......@@ -209,7 +210,7 @@ static QJsonObject renameParams(const QUrl &document, const LSPPosition &pos,
}
static QJsonObject codeActionParams(const QUrl &document, const LSPRange &range,
QList<QString> kinds, QList<LSPDiagnostic> diagnostics)
const QList<QString>& kinds, const QList<LSPDiagnostic>& diagnostics)
{
auto params = textDocumentParams(document);
params[MEMBER_RANGE] = to_json(range);
......@@ -1058,7 +1059,7 @@ public:
}
RequestHandle documentRename(const QUrl &document, const LSPPosition &pos,
const QString newName, const GenericReplyHandler &h)
const QString& newName, const GenericReplyHandler &h)
{
auto params = renameParams(document, pos, newName);
return send(init_request(QStringLiteral("textDocument/rename"), params), h);
......@@ -1068,7 +1069,7 @@ public:
const QList<QString> &kinds, QList<LSPDiagnostic> diagnostics,
const GenericReplyHandler &h)
{
auto params = codeActionParams(document, range, kinds, diagnostics);
auto params = codeActionParams(document, range, kinds, std::move(diagnostics));
return send(init_request(QStringLiteral("textDocument/codeAction"), params), h);
}
......@@ -1323,7 +1324,7 @@ LSPClientServer::documentOnTypeFormatting(const QUrl &document, const LSPPositio
}
LSPClientServer::RequestHandle
LSPClientServer::documentRename(const QUrl &document, const LSPPosition &pos, const QString newName,
LSPClientServer::documentRename(const QUrl &document, const LSPPosition &pos, const QString& newName,
const QObject *context, const WorkspaceEditReplyHandler &h)
{
return d->documentRename(document, pos, newName, make_handler(h, context, parseWorkSpaceEdit));
......@@ -1334,7 +1335,7 @@ LSPClientServer::documentCodeAction(const QUrl &document, const LSPRange &range,
const QList<QString> &kinds, QList<LSPDiagnostic> diagnostics,
const QObject *context, const CodeActionReplyHandler &h)
{
return d->documentCodeAction(document, range, kinds, diagnostics,
return d->documentCodeAction(document, range, kinds, std::move(diagnostics),
make_handler(h, context, parseCodeAction));
}
......
......@@ -150,7 +150,7 @@ public:
QChar lastChar, const LSPFormattingOptions &options,
const QObject *context, const FormattingReplyHandler &h);
RequestHandle documentRename(const QUrl &document, const LSPPosition &pos,
const QString newName, const QObject *context,
const QString& newName, const QObject *context,
const WorkspaceEditReplyHandler &h);
RequestHandle documentCodeAction(const QUrl &document, const LSPRange &range,
......
......@@ -626,7 +626,7 @@ private:
emit serverChanged();
}
void trackDocument(KTextEditor::Document *doc, QSharedPointer<LSPClientServer> server)
void trackDocument(KTextEditor::Document *doc, const QSharedPointer<LSPClientServer>& server)
{
auto it = m_docs.find(doc);
if (it == m_docs.end()) {
......
......@@ -41,6 +41,7 @@
#include <QStandardItemModel>
#include <memory>
#include <utility>
class LSPClientViewTrackerImpl : public LSPClientViewTracker
{
......@@ -175,7 +176,7 @@ public:
QSharedPointer<LSPClientServerManager> manager)
: m_plugin(plugin),
m_mainWindow(mainWin),
m_serverManager(manager),
m_serverManager(std::move(manager)),
m_outline(new QStandardItemModel())
{
m_toolview.reset(m_mainWindow->createToolView(
......@@ -377,7 +378,7 @@ public:
setModel(newModel);
}
void setModel(std::shared_ptr<QStandardItemModel> newModel)
void setModel(const std::shared_ptr<QStandardItemModel>& newModel)
{
Q_ASSERT(newModel);
......@@ -548,7 +549,7 @@ private Q_SLOTS:
QObject *LSPClientSymbolView::new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin,
QSharedPointer<LSPClientServerManager> manager)
{
return new LSPClientSymbolViewImpl(plugin, mainWin, manager);
return new LSPClientSymbolViewImpl(plugin, mainWin, std::move(manager));
}
#include "lspclientsymbolview.moc"
......@@ -33,6 +33,7 @@
#include <QPlainTextDocumentLayout>
#include <QJsonDocument>
#include <QJsonParseError>
#include <utility>
KateProject::KateProject(ThreadWeaver::Queue *weaver)
: QObject()
......@@ -156,12 +157,12 @@ bool KateProject::load(const QVariantMap &globalProject, bool force)
return true;
}
void KateProject::loadProjectDone(KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item)
void KateProject::loadProjectDone(const KateProjectSharedQStandardItem& topLevel, KateProjectSharedQMapStringItem file2Item)
{
m_model.clear();
m_model.invisibleRootItem()->appendColumn(topLevel->takeColumn(0));
m_file2Item = file2Item;
m_file2Item = std::move(file2Item);
/**
* readd the documents that are open atm
......@@ -179,7 +180,7 @@ void KateProject::loadIndexDone(KateProjectSharedProjectIndex projectIndex)
/**
* move to our project
*/
m_projectIndex = projectIndex;
m_projectIndex = std::move(projectIndex);
/**
* notify external world that data is available
......
......@@ -197,7 +197,7 @@ private Q_SLOTS:
* @param topLevel new toplevel element for model
* @param file2Item new file => item mapping
*/
void loadProjectDone(KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item);
void loadProjectDone(const KateProjectSharedQStandardItem& topLevel, KateProjectSharedQMapStringItem file2Item);
/**
* Used for worker to send back the results of index loading
......
......@@ -426,7 +426,7 @@ QStringList PseudoDTD::entities(const QString &start)
QMap<QString, QString>::Iterator it;
for (it = m_entityList.begin(); it != m_entityList.end(); ++it) {
if ((*it).startsWith(start)) {
QString str = it.key();
const QString& str = it.key();
/* TODO: show entities as unicode character
if( !it.data().isEmpty() ) {
//str += " -- " + it.data();
......
......@@ -285,7 +285,7 @@ bool KateDocManager::closeDocument(KTextEditor::Document *doc, bool closeUrl)
return closeDocuments(documents, closeUrl);
}
bool KateDocManager::closeDocumentList(QList<KTextEditor::Document *> documents)
bool KateDocManager::closeDocumentList(const QList<KTextEditor::Document *>& documents)
{
QList<KTextEditor::Document *> modifiedDocuments;
foreach(KTextEditor::Document * document, documents) {
......
......@@ -82,7 +82,7 @@ public:
bool closeDocument(KTextEditor::Document *, bool closeUrl = true);
bool closeDocuments(const QList<KTextEditor::Document *> &documents, bool closeUrl = true);
bool closeDocumentList(QList<KTextEditor::Document *> documents);
bool closeDocumentList(const QList<KTextEditor::Document *>& documents);
bool closeAllDocuments(bool closeUrl = true);
bool closeOtherDocuments(KTextEditor::Document *);
......
......@@ -126,7 +126,7 @@ private:
KTextEditor::Document *m_document;
};
KateSaveModifiedDialog::KateSaveModifiedDialog(QWidget *parent, QList<KTextEditor::Document *> documents):
KateSaveModifiedDialog::KateSaveModifiedDialog(QWidget *parent, const QList<KTextEditor::Document *>& documents):
QDialog(parent)
{
setWindowTitle(i18n("Save Documents"));
......
......@@ -33,7 +33,7 @@ class KateSaveModifiedDialog: public QDialog
{
Q_OBJECT
public:
KateSaveModifiedDialog(QWidget *parent, QList<KTextEditor::Document *> documents);
KateSaveModifiedDialog(QWidget *parent, const QList<KTextEditor::Document *>& documents);
~KateSaveModifiedDialog() override;
static bool queryClose(QWidget *parent, const QList<KTextEditor::Document *> &documents);
protected:
......
......@@ -131,7 +131,7 @@ void KateSessionManageDialog::filterChanged()
void KateSessionManageDialog::done(int result)
{
for (auto session : qAsConst(m_deleteList)) {
for (const auto& session : qAsConst(m_deleteList)) {
KateApp::self()->sessionManager()->deleteSession(session);
}
m_deleteList.clear(); // May not needed, but anyway
......
......@@ -92,7 +92,7 @@ void KateSessionManager::updateSessionList()
bool changed = false;
// Add new sessions to our list
for (const QString session : qAsConst(list)) {
for (const QString& session : qAsConst(list)) {
if (!m_sessions.contains(session)) {
const QString file = sessionFileForName(session);
m_sessions.insert(session, KateSession::create(file, session));
......@@ -100,7 +100,7 @@ void KateSessionManager::updateSessionList()
}
}
// Remove gone sessions from our list
for (const QString session : m_sessions.keys()) {
for (const QString& session : m_sessions.keys()) {
if ((list.indexOf(session) < 0) && (m_sessions.value(session) != activeSession())) {
m_sessions.remove(session);
changed = true;
......@@ -337,7 +337,7 @@ QString KateSessionManager::renameSession(KateSession::Ptr session, const QStrin
void KateSessionManager::saveSessionTo(KConfig *sc) const
{
// Clear the session file to avoid to accumulate outdated entries
for (auto group : sc->groupList()) {
for (const auto& group : sc->groupList()) {
sc->deleteGroup(group);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment