Skip to content

Commit 902f46b

Browse files
authored
some minor QRegularExpression usage optimizations and cleanups (danmar#3999)
1 parent 375df3a commit 902f46b

5 files changed

Lines changed: 15 additions & 9 deletions

File tree

gui/checkthread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
307307
{
308308
QList<ErrorItem> errorItems;
309309
ErrorItem errorItem;
310-
const QRegularExpression r1("^(.+):([0-9]+):([0-9]+): (note|warning|error|fatal error): (.*)$");
311-
const QRegularExpression r2("^(.*)\\[([a-zA-Z0-9\\-_\\.]+)\\]$");
310+
static const QRegularExpression r1("^(.+):([0-9]+):([0-9]+): (note|warning|error|fatal error): (.*)$");
311+
static const QRegularExpression r2("^(.*)\\[([a-zA-Z0-9\\-_\\.]+)\\]$");
312312
QTextStream in(&err, QIODevice::ReadOnly);
313313
while (!in.atEnd()) {
314314
QString line = in.readLine();

gui/libraryaddfunctiondialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LibraryAddFunctionDialog::LibraryAddFunctionDialog(QWidget *parent) :
2828
mUi(new Ui::LibraryAddFunctionDialog)
2929
{
3030
mUi->setupUi(this);
31-
const QRegularExpression rx(NAMES);
31+
static const QRegularExpression rx(NAMES);
3232
QValidator *validator = new QRegularExpressionValidator(rx, this);
3333
mUi->functionName->setValidator(validator);
3434
}

gui/mainwindow.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ void MainWindow::handleCLIParams(const QStringList &params)
262262
} else {
263263
loadResults(logFile);
264264
}
265-
} else if ((index = params.indexOf(QRegularExpression(".*\\.cppcheck$", QRegularExpression::CaseInsensitiveOption), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) {
265+
} else if ((index = params.indexOf(QRegularExpression(".*\\.cppcheck$", QRegularExpression::CaseInsensitiveOption))) >= 0 && index < params.length() && QFile(params[index]).exists()) {
266266
loadProjectFile(params[index]);
267-
} else if ((index = params.indexOf(QRegularExpression(".*\\.xml$", QRegularExpression::CaseInsensitiveOption), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) {
267+
} else if ((index = params.indexOf(QRegularExpression(".*\\.xml$", QRegularExpression::CaseInsensitiveOption))) >= 0 && index < params.length() && QFile(params[index]).exists()) {
268268
loadResults(params[index],QDir::currentPath());
269269
} else
270270
doAnalyzeFiles(params);
@@ -1142,8 +1142,11 @@ void MainWindow::clearResults()
11421142
if (mProjectFile && !mProjectFile->getBuildDir().isEmpty()) {
11431143
QDir dir(QFileInfo(mProjectFile->getFilename()).absolutePath() + '/' + mProjectFile->getBuildDir());
11441144
for (const QString& f: dir.entryList(QDir::Files)) {
1145-
if (!f.endsWith("files.txt") && !QRegularExpression("^.*.s[0-9]+$").match(f).hasMatch())
1146-
dir.remove(f);
1145+
if (!f.endsWith("files.txt")) {
1146+
static const QRegularExpression rx("^.*.s[0-9]+$");
1147+
if (!rx.match(f).hasMatch())
1148+
dir.remove(f);
1149+
}
11471150
}
11481151
}
11491152
mUI->mResults->clear(true);

gui/statsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString
406406
QTextStream in(&f);
407407
while (!in.atEnd()) {
408408
QString line = in.readLine();
409-
const QRegularExpression rxdate("^\\[(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\\]$");
409+
static const QRegularExpression rxdate("^\\[(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\\]$");
410410
const QRegularExpressionMatch matchRes = rxdate.match(line);
411411
if (matchRes.hasMatch()) {
412412
int y = matchRes.captured(3).toInt();

tools/triage/mainwindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ void MainWindow::load(QTextStream &textStream)
111111
if (!errorMessage.isEmpty())
112112
mAllErrors << errorMessage;
113113
errorMessage.clear();
114-
} else if (!url.isEmpty() && QRegularExpression("^.*: (error|warning|style|note):.*$").match(line).hasMatch()) {
114+
} else if (!url.isEmpty()) {
115+
static const QRegularExpression severityRe("^.*: (error|warning|style|note):.*$");
116+
if (severityRe.match(line).hasMatch())
117+
continue;
115118
const QRegularExpressionMatch matchRes = mVersionRe.match(line);
116119
if (matchRes.hasMatch()) {
117120
const QString version = matchRes.captured(1);

0 commit comments

Comments
 (0)