Skip to content

Commit

Permalink
Improve efficiency, readability, and performance in several modules
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
merttozer committed Jul 31, 2024
1 parent 53e55be commit de3916b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Executor::Executor(const std::list<FileWithDetails> &files, const std::list<File
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{
// the two inputs may only be used exclusively
assert(!(!files.empty() && !fileSettings.empty()));
assert(files.empty() || fileSettings.empty());
}

// TODO: this logic is duplicated in CppCheck::reportErr()
Expand Down
6 changes: 3 additions & 3 deletions cli/singleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ unsigned int SingleExecutor::check()
std::size_t processedsize = 0;
unsigned int c = 0;

for (std::list<FileWithDetails>::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);
Expand Down
9 changes: 2 additions & 7 deletions gui/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

AboutDialog::AboutDialog(const QString &version, const QString &extraVersion, QWidget *parent)
: QDialog(parent)
, mUI(new Ui::About)
, mUI(std::make_unique<Ui::About>())
{
mUI->setupUi(this);

Expand All @@ -39,9 +39,4 @@ AboutDialog::AboutDialog(const QString &version, const QString &extraVersion, QW
QString url = "<a href=\"https://cppcheck.sourceforge.io/\">https://cppcheck.sourceforge.io/</a>";
mUI->mHomepage->setText(mUI->mHomepage->text().arg(url));
connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &AboutDialog::accept);
}

AboutDialog::~AboutDialog()
{
delete mUI;
}
}
5 changes: 3 additions & 2 deletions gui/aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QDialog>
#include <QObject>
#include <QString>
#include <memory>

class QWidget;
namespace Ui {
Expand All @@ -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<Ui::About> mUI;
};
/// @}
#endif // ABOUT_DIALOG_H
8 changes: 1 addition & 7 deletions gui/applicationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ApplicationDialog::ApplicationDialog(const QString &title,
Application &app,
QWidget *parent) :
QDialog(parent),
mUI(new Ui::ApplicationDialog),
mUI(std::make_unique<Ui::ApplicationDialog>()),
mApplication(app)
{
mUI->setupUi(this);
Expand All @@ -50,12 +50,6 @@ ApplicationDialog::ApplicationDialog(const QString &title,
adjustSize();
}


ApplicationDialog::~ApplicationDialog()
{
delete mUI;
}

void ApplicationDialog::browse()
{
QString filter;
Expand Down
5 changes: 3 additions & 2 deletions gui/applicationdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QDialog>
#include <QObject>
#include <QString>
#include <memory>

class QWidget;
class Application;
Expand Down Expand Up @@ -51,7 +52,7 @@ class ApplicationDialog : public QDialog {
ApplicationDialog(const QString &title,
Application &app,
QWidget *parent = nullptr);
~ApplicationDialog() override;
~ApplicationDialog() override = default;

protected slots:

Expand All @@ -69,7 +70,7 @@ protected slots:
* @brief UI from the Qt designer
*
*/
Ui::ApplicationDialog* mUI;
std::unique_ptr<Ui::ApplicationDialog> mUI;

private:

Expand Down

0 comments on commit de3916b

Please sign in to comment.