optimization?

This commit is contained in:
RickyRister 2025-03-12 02:30:31 -07:00
parent f50d2acf8a
commit 2f1d97b5e0

View file

@ -23,16 +23,26 @@
*/ */
bool parseCipt(const QString &name, const QString &text) bool parseCipt(const QString &name, const QString &text)
{ {
// try to split shortname on all non-alphanumeric characters (including _) // Try to split shortname on most non-alphanumeric characters (including _)
static auto SHORTNAME_DIVIDERS = QRegularExpression("[^\\w]|_"); static QSet<QChar> exceptions = {'\'', '\"'};
static auto isShortnameDivider = [](const QChar &c) {
return c == '_' || (!c.isLetterOrNumber() && !exceptions.contains(c));
};
// Try all possible shortnames. // Try all possible shortnames.
// This also handles the case of extra text appended at end. // This also handles the case of extra text appended at end.
QStringList possibleNames; QStringList possibleNames;
qsizetype i = 0; bool inAlphanumericPart = true;
while ((i = name.indexOf(SHORTNAME_DIVIDERS, i)) != -1) { for (int i = 0; i < name.length(); ++i) {
if (isShortnameDivider(name.at(i))) {
if (inAlphanumericPart) {
// only add to names on a "falling edge", in order to reduce the amount of redundant splits
possibleNames.append(QRegularExpression::escape(name.first(i))); possibleNames.append(QRegularExpression::escape(name.first(i)));
++i; inAlphanumericPart = false;
}
} else {
inAlphanumericPart = true;
}
} }
// and the full name // and the full name