From 2f1d97b5e0a40638ec1c04f2a357755e28bbe60a Mon Sep 17 00:00:00 2001 From: RickyRister Date: Wed, 12 Mar 2025 02:30:31 -0700 Subject: [PATCH] optimization? --- oracle/src/parsehelpers.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/oracle/src/parsehelpers.cpp b/oracle/src/parsehelpers.cpp index 893378eec..fa778e8f4 100644 --- a/oracle/src/parsehelpers.cpp +++ b/oracle/src/parsehelpers.cpp @@ -23,16 +23,26 @@ */ bool parseCipt(const QString &name, const QString &text) { - // try to split shortname on all non-alphanumeric characters (including _) - static auto SHORTNAME_DIVIDERS = QRegularExpression("[^\\w]|_"); + // Try to split shortname on most non-alphanumeric characters (including _) + static QSet exceptions = {'\'', '\"'}; + static auto isShortnameDivider = [](const QChar &c) { + return c == '_' || (!c.isLetterOrNumber() && !exceptions.contains(c)); + }; // Try all possible shortnames. // This also handles the case of extra text appended at end. QStringList possibleNames; - qsizetype i = 0; - while ((i = name.indexOf(SHORTNAME_DIVIDERS, i)) != -1) { - possibleNames.append(QRegularExpression::escape(name.first(i))); - ++i; + bool inAlphanumericPart = true; + 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))); + inAlphanumericPart = false; + } + } else { + inAlphanumericPart = true; + } } // and the full name