Skip to content

ThreadResult: use FileWithDetails for mFiles #7598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,27 @@ void CheckThread::run()
return;
}

QString file = mResult.getNextFile();
while (!file.isEmpty() && mState == Running) {
qDebug() << "Checking file" << file;
cppcheck.check(FileWithDetails(file.toStdString(), Path::identify(file.toStdString(), mSettings.cppHeaderProbe), 0));
runAddonsAndTools(mSettings, nullptr, file);
emit fileChecked(file);
const FileWithDetails* file = nullptr;
mResult.getNextFile(file);
while (file && mState == Running) {
const std::string& fname = file->spath();
qDebug() << "Checking file" << QString::fromStdString(fname);
cppcheck.check(*file);
runAddonsAndTools(mSettings, nullptr, QString::fromStdString(fname));
emit fileChecked(QString::fromStdString(fname));

if (mState == Running)
file = mResult.getNextFile();
mResult.getNextFile(file);
}

const FileSettings* fileSettings = nullptr;
mResult.getNextFileSettings(fileSettings);
while (fileSettings && mState == Running) {
file = QString::fromStdString(fileSettings->filename());
qDebug() << "Checking file" << file;
const std::string& fname = fileSettings->filename();
qDebug() << "Checking file" << QString::fromStdString(fname);
cppcheck.check(*fileSettings);
runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fileSettings->filename()));
emit fileChecked(file);
runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fname));
emit fileChecked(QString::fromStdString(fname));

if (mState == Running)
mResult.getNextFileSettings(fileSettings);
Expand Down
22 changes: 14 additions & 8 deletions gui/threadresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ void ThreadResult::reportErr(const ErrorMessage &msg)
emit debugError(item);
}

QString ThreadResult::getNextFile()
void ThreadResult::getNextFile(const FileWithDetails*& file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return the pointer instead of using outparam?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to keep it in line with the existing code here and the duplicated code in ThreadData from threadexecutor.cpp.

{
std::lock_guard<std::mutex> locker(mutex);
if (mFiles.isEmpty()) {
return QString();
file = nullptr;
if (mItNextFile == mFiles.cend()) {
return;
}

return mFiles.takeFirst();
file = &(*mItNextFile);
++mItNextFile;
}

void ThreadResult::getNextFileSettings(const FileSettings*& fs)
Expand All @@ -82,15 +83,20 @@ void ThreadResult::getNextFileSettings(const FileSettings*& fs)
void ThreadResult::setFiles(const QStringList &files)
{
std::lock_guard<std::mutex> locker(mutex);
mFiles = files;
std::list<FileWithDetails> fdetails;
std::transform(files.cbegin(), files.cend(), std::back_inserter(fdetails), [](const QString& f) {
return FileWithDetails{f.toStdString(), Path::identify(f.toStdString(), false), static_cast<std::size_t>(QFile(f).size())}; // TODO: provide Settings::cppHeaderProbe
});
mFiles = std::move(fdetails);
mItNextFile = mFiles.cbegin();
mProgress = 0;
mFilesChecked = 0;
mTotalFiles = files.size();

// Determine the total size of all of the files to check, so that we can
// show an accurate progress estimate
quint64 sizeOfFiles = std::accumulate(files.begin(), files.end(), 0, [](quint64 total, const QString& file) {
return total + QFile(file).size();
quint64 sizeOfFiles = std::accumulate(mFiles.cbegin(), mFiles.cend(), 0, [](quint64 total, const FileWithDetails& file) {
return total + file.size();
});
mMaxProgress = sizeOfFiles;
}
Expand Down
6 changes: 3 additions & 3 deletions gui/threadresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ class ThreadResult : public QObject, public ErrorLogger {

/**
* @brief Get next unprocessed file
* @return File path
*/
QString getNextFile();
void getNextFile(const FileWithDetails*& file);

void getNextFileSettings(const FileSettings*& fs);

Expand Down Expand Up @@ -138,7 +137,8 @@ public slots:
* @brief List of files to check
*
*/
QStringList mFiles;
std::list<FileWithDetails> mFiles;
std::list<FileWithDetails>::const_iterator mItNextFile;

std::list<FileSettings> mFileSettings;
std::list<FileSettings>::const_iterator mItNextFileSettings;
Expand Down
Loading