[Bug 72831] File Groups performance bad in some cases

Jens Dagerbo jens.dagerbo at swipnet.se
Wed Jan 21 08:47:04 UTC 2004


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
      
http://bugs.kde.org/show_bug.cgi?id=72831      
jens.dagerbo at swipnet.se changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From jens.dagerbo at swipnet.se  2004-01-21 08:45 -------
Subject: kdevelop/parts/fileview

CVS commit by dagerbo: 

Improve File Groups plugin performance. Closes bug 72831.

Main part of patch written by Jonas Jacobi. 

CCMAIL: 72831-done at bugs.kde.org


  M +57 -10    filegroupswidget.cpp   1.23


--- kdevelop/parts/fileview/filegroupswidget.cpp  #1.22:1.23
@@ -44,4 +44,32 @@ static const char *translations[] = {
 };
 
+class FileComparator {
+public:
+        virtual ~FileComparator(){
+        };
+        virtual bool matches(const QString& name) const = 0;
+};
+
+class RegExpComparator : public FileComparator {
+public: 
+        RegExpComparator(const QString& pattern) : m_exp(pattern, true, true){
+        }
+        bool matches(const QString& name) const{
+                return m_exp.exactMatch(name);
+        }
+private:
+        const QRegExp m_exp;
+};
+
+class EndingComparator : public FileComparator {
+public:
+        EndingComparator(const QString& pattern) : m_pattern ( pattern){
+        }
+        bool matches(const QString& name) const{
+                return name.endsWith(m_pattern);
+        }
+private:
+        const QString m_pattern;
+};
 
 class FileViewFolderItem : public QListViewItem
@@ -52,5 +80,5 @@ public:
 
 private:
-    QStringList patterns;
+    QPtrList<FileComparator> m_patterns;
 };
 
@@ -60,5 +88,28 @@ FileViewFolderItem::FileViewFolderItem(Q
 {
     setPixmap(0, SmallIcon("folder"));
-    patterns = QStringList::split(';', pattern);
+    m_patterns.setAutoDelete(true);
+    QStringList patternstring = QStringList::split(';', pattern);
+    QStringList::ConstIterator theend = patternstring.end();
+    for (QStringList::ConstIterator ci = patternstring.begin(); ci != theend; ++ci)
+        {
+                QString pattern = *ci;
+                QString tail = pattern.right( pattern.length() - 1 );
+                
+                if ( (tail).contains('*') || pattern.contains('?') || pattern.contains('[') || pattern.contains(']') )
+                {
+                        m_patterns.append( new RegExpComparator( pattern ) );
+                }
+                else
+                {
+                        if ( pattern.startsWith("*") )
+                        {
+                                m_patterns.append( new EndingComparator( tail ) );
+                        }
+                        else
+                        {
+                                m_patterns.append( new EndingComparator( pattern ) );
+                        }
+                }
+    }
 }
 
@@ -69,12 +120,8 @@ bool FileViewFolderItem::matches(const Q
     QString fName = QFileInfo(fileName).filePath();
 
-    QStringList::ConstIterator it;
-    for (it = patterns.begin(); it != patterns.end(); ++it) {
-        // The regexp objects could be created already
-        // in the constructor
-        QRegExp re(*it, true, true);
-        if (re.exactMatch(fName))
+    QPtrList<FileComparator>::ConstIterator theend = m_patterns.end();
+    for (QPtrList<FileComparator>::ConstIterator ci = m_patterns.begin(); ci != theend; ++ci) 
+        if ((*ci)->matches(fName))
             return true;
-    }
 
     return false;




More information about the KDevelop-devel mailing list