[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: KDE/kdelibs/kate/mode
From: Dominik Haumann <dhdev () gmx ! de>
Date: 2007-10-16 19:18:24
Message-ID: 200710162118.24295.dhdev () gmx ! de
[Download RAW message or body]
On Tuesday 16 October 2007, Sebastian Pipping wrote:
> SVN commit 725946 by sping:
>
> Speed up mode detection, review wanted
how much faster is it? i.e. is it really worth it? :)
Sorry that I didn't reply to your mail, but I've barely time atm :(
> M +26 -22 katemodemanager.cpp
> M +6 -0 katemodemanager.h
>
>
> --- trunk/KDE/kdelibs/kate/mode/katemodemanager.cpp #725945:725946
> @@ -277,40 +277,44 @@
> return "";
> }
>
> +/*static*/ QString KateModeManager::reverse(const QString & text) {
> + const int len = text.length();
> + QString res;
> + res.reserve(len);
> + for (int i = len - 1; i >= 0; i--) {
> + res.append(text[i]);
> + }
> + return res;
> +}
> +
> QString KateModeManager::wildcardsFind (const QString &fileName)
> {
> - QList<KateFileType*> types;
> + const QString reversedFilename = reverse(fileName);
>
> + QRegExp re;
> + re.setCaseSensitivity(Qt::CaseSensitive);
> + re.setPatternSyntax(QRegExp::Wildcard);
> +
> + KateFileType * match = NULL;
> + int minPrio = -1;
> foreach (KateFileType *type, m_types)
> {
> - foreach (QString wildcard, type->wildcards)
> - {
> - // anders: we need to be sure to match the end of string, as eg a
> css file - // would otherwise end up with the c hl
> - QRegExp re(wildcard, Qt::CaseSensitive, QRegExp::Wildcard);
> - if ( ( re.indexIn( fileName ) > -1 ) && ( re.matchedLength() ==
> (int)fileName.length() ) ) - types.append (type);
> + if (type->priority <= minPrio) {
> + continue;
> }
> - }
>
> - if ( !types.isEmpty() )
> - {
> - int pri = -1;
> - QString name;
> -
> - foreach (KateFileType *type, types)
> + foreach (QString wildcard, type->wildcards)
> {
> - if (type->priority > pri)
> - {
> - pri = type->priority;
> - name = type->name;
> + re.setPattern(reverse(wildcard));
> + if (re.exactMatch(reversedFilename)) {
> + match = type;
> + minPrio = type->priority;
> + break;
> }
> }
> -
> - return name;
> }
>
> - return "";
> + return (match == NULL) ? "" : match->name;
> }
>
> const KateFileType& KateModeManager::fileType(const QString &name) const
> --- trunk/KDE/kdelibs/kate/mode/katemodemanager.h #725945:725946
> @@ -77,6 +77,12 @@
> private:
> QList<KateFileType *> m_types;
> QHash<QString, KateFileType *> m_name2Type;
> +
> + /**
> + * Reverses a string on char level, i.e. "abc" becomes "cba".
> + */
> + static QString reverse(const QString & text);
> +
> };
>
> #endif
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic