refact: optimize regular expression initialization

add profiling test.

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-08-21 18:38:27 +08:00
committed by Comix
parent 06ee5e5899
commit 2bdb9e99ee
6 changed files with 50 additions and 7 deletions

View File

@ -59,8 +59,12 @@ DesktopErrorCode DesktopEntry::parseEntry(const QString &str, decltype(m_entryMa
const static auto validKey =
QString("^%1(?:\\[(?<LOCALE>%2%3?%4?%5?)\\])?$").arg(MainKey).arg(Language).arg(Country).arg(Encoding).arg(Modifier);
// example: https://regex101.com/r/hylOay/1
QRegularExpression re{validKey};
re.optimize();
static QRegularExpression re = []() -> QRegularExpression {
QRegularExpression tmp{validKey};
tmp.optimize();
return tmp;
}();
auto matcher = re.match(keyStr);
if (!matcher.hasMatch()) {
#ifdef DEBUG_MODE
@ -216,8 +220,8 @@ DesktopErrorCode DesktopEntry::parse(QTextStream &stream) noexcept
continue;
}
if (line.startsWith("[")) {
if (!line.endsWith("]")) {
if (line[0] == '[') {
if (!(line[line.size() - 1] == ']')) {
return DesktopErrorCode::GroupHeaderInvalid;
}
currentGroup = parserGroupHeader(line);

View File

@ -19,10 +19,13 @@
#include <QDBusObjectPath>
#include <unistd.h>
#include <QUuid>
#include <QLoggingCategory>
#include <sys/stat.h>
#include "constant.h"
#include "config.h"
Q_DECLARE_LOGGING_CATEGORY(DDEAMProf)
using IconMap = QMap<QString, QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>;
using ObjectMap = QMap<QDBusObjectPath, QStringList>;