From de3916ba86bcb6e1bb0aa569da1ac5d2191af74c Mon Sep 17 00:00:00 2001 From: merttozer Date: Wed, 31 Jul 2024 15:29:38 +0300 Subject: [PATCH] Improve efficiency, readability, and performance in several modules - executor.cpp: - Used initializer lists in the constructor - Simplified assertion and used std::lock_guard for mutex - singleexecutor.cpp and singleexecutor.h: - Simplified constructor initialization - Used range-based for loops and std::accumulate with lambda for better readability and efficiency - aboutdialog.cpp and aboutdialog.h: - Replaced raw pointers with std::unique_ptr - Simplified string formatting and used modern C++ features - Improved memory management and added const correctness - applicationdialog.cpp and applicationdialog.h: - Replaced raw pointers with std::unique_ptr - Improved memory management and added const correctness --- cli/executor.cpp | 2 +- cli/singleexecutor.cpp | 6 +++--- gui/aboutdialog.cpp | 9 ++------- gui/aboutdialog.h | 5 +++-- gui/applicationdialog.cpp | 8 +------- gui/applicationdialog.h | 5 +++-- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/cli/executor.cpp b/cli/executor.cpp index d60e901e8e9..20fced7db6b 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -34,7 +34,7 @@ Executor::Executor(const std::list &files, const std::list::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) { - result += mCppcheck.check(*i); - processedsize += i->size(); + for (const auto& file : mFiles) { + result += mCppcheck.check(file); + processedsize += file.size(); ++c; if (!mSettings.quiet) reportStatus(c, mFiles.size(), processedsize, totalfilesize); diff --git a/gui/aboutdialog.cpp b/gui/aboutdialog.cpp index d93d8e8a32f..26863e4393e 100644 --- a/gui/aboutdialog.cpp +++ b/gui/aboutdialog.cpp @@ -25,7 +25,7 @@ AboutDialog::AboutDialog(const QString &version, const QString &extraVersion, QWidget *parent) : QDialog(parent) - , mUI(new Ui::About) + , mUI(std::make_unique()) { mUI->setupUi(this); @@ -39,9 +39,4 @@ AboutDialog::AboutDialog(const QString &version, const QString &extraVersion, QW QString url = "https://cppcheck.sourceforge.io/"; mUI->mHomepage->setText(mUI->mHomepage->text().arg(url)); connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &AboutDialog::accept); -} - -AboutDialog::~AboutDialog() -{ - delete mUI; -} +} \ No newline at end of file diff --git a/gui/aboutdialog.h b/gui/aboutdialog.h index 7e46839d725..3e83c89fa51 100644 --- a/gui/aboutdialog.h +++ b/gui/aboutdialog.h @@ -22,6 +22,7 @@ #include #include #include +#include class QWidget; namespace Ui { @@ -42,10 +43,10 @@ class AboutDialog : public QDialog { const QString &extraVersion, QWidget *parent = nullptr); - ~AboutDialog() override; + ~AboutDialog() override = default; private: - Ui::About* mUI; + std::unique_ptr mUI; }; /// @} #endif // ABOUT_DIALOG_H diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp index bc8804d6f97..6e7e4905e93 100644 --- a/gui/applicationdialog.cpp +++ b/gui/applicationdialog.cpp @@ -35,7 +35,7 @@ ApplicationDialog::ApplicationDialog(const QString &title, Application &app, QWidget *parent) : QDialog(parent), - mUI(new Ui::ApplicationDialog), + mUI(std::make_unique()), mApplication(app) { mUI->setupUi(this); @@ -50,12 +50,6 @@ ApplicationDialog::ApplicationDialog(const QString &title, adjustSize(); } - -ApplicationDialog::~ApplicationDialog() -{ - delete mUI; -} - void ApplicationDialog::browse() { QString filter; diff --git a/gui/applicationdialog.h b/gui/applicationdialog.h index 4bc68bf5b13..3005813d46f 100644 --- a/gui/applicationdialog.h +++ b/gui/applicationdialog.h @@ -22,6 +22,7 @@ #include #include #include +#include class QWidget; class Application; @@ -51,7 +52,7 @@ class ApplicationDialog : public QDialog { ApplicationDialog(const QString &title, Application &app, QWidget *parent = nullptr); - ~ApplicationDialog() override; + ~ApplicationDialog() override = default; protected slots: @@ -69,7 +70,7 @@ protected slots: * @brief UI from the Qt designer * */ - Ui::ApplicationDialog* mUI; + std::unique_ptr mUI; private: