[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdevelop/3.4/languages/cpp
From:       David Nolden <david.nolden.kde () art-master ! de>
Date:       2007-01-20 17:15:09
Message-ID: 1169313309.760760.21640.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 625648 by zwabel:

limit the sizes of the problem-reporter's lists to ca. 300, so kdevelop doesn't spend \
most of the cpu-time with handling the lists while parsing with preprocess-header \
mode activated.

 M  +24 -3     problemreporter.cpp  
 M  +16 -6     problemreporter.h  


--- branches/kdevelop/3.4/languages/cpp/problemreporter.cpp #625647:625648
@@ -244,11 +244,28 @@
 	initCurrentList();
 }
 
-void EfficientKListView::removeAllItems( const QString& str ) {
-	std::pair<Map::iterator, Map::iterator> p = m_map.equal_range( str );
+void EfficientKListView::limitSize( int size )
+{
+	int safety = 0;
+	if( m_map.size() <= size + 50 ) return;
 	
+	QMap<int, HashedString> backMap;
+	for( InsertionMap::const_iterator it = m_insertionNumbers.begin(); it != \
m_insertionNumbers.end(); ++it ) +		backMap[ (*it).second ] = (*it).first;
+
+	for( QMap<int, HashedString>::const_iterator it = backMap.begin(); it != \
backMap.end() && m_map.size() > size; ++it ) +		removeAllItems( (*it).str() );
+}
+
+void EfficientKListView::removeAllItems( const QString& str )
+{
+	HashedString h(str);
+	m_insertionNumbers.erase( h ) ;
+	
+	std::pair<Map::iterator, Map::iterator> p = m_map.equal_range( h );
+	
 	for( Map::iterator it = p.first; it != p.second; ++it ) {
-		m_list->removeItem( (*p.first).second );
+		delete( (*it).second );
 	}
 
 	m_map.erase( p.first, p.second );
@@ -260,6 +277,10 @@
 	
 	kdDebug(9007) << "ProblemReporter::removeAllProblems()" << relFileName << endl;
 
+	m_errorList.limitSize( 300 );
+	m_fixmeList.limitSize( 300 );
+	m_todoList.limitSize( 300 );
+	
 	m_errorList.removeAllItems( relFileName );
 	m_fixmeList.removeAllItems( relFileName );
 	m_todoList.removeAllItems( relFileName );
--- branches/kdevelop/3.4/languages/cpp/problemreporter.h #625647:625648
@@ -24,6 +24,8 @@
 #include <qguardedptr.h>
 #include <qdatetime.h>
 #include <map>
+#include <ext/hash_map>
+#include <lib/interfaces/hashedstring.h>
 
 class CppSupportPart;
 class QTimer;
@@ -36,9 +38,9 @@
 
 class EfficientKListView {
 public:
-    typedef std::multimap<QString, QListViewItem*> Map;
+    typedef __gnu_cxx::hash_multimap<HashedString, QListViewItem*> Map;
     typedef std::pair< Map::const_iterator, Map::const_iterator > Range;
-    EfficientKListView( KListView* list = 0 ) : m_list( list ) {
+    EfficientKListView( KListView* list = 0 ) : m_list( list ), m_insertionNumber( 0 \
) {  }
     
     EfficientKListView& operator = ( KListView* list ) {
@@ -63,21 +65,29 @@
     }
     
     void addItem( const QString& str, QListViewItem* item ) {
-        m_map.insert( std::make_pair( str, item ) );
+        HashedString h( str );
+        m_insertionNumbers[h] = ++m_insertionNumber;
+        m_map.insert( std::make_pair( h, item ) );
     }
     
     Range getRange( const QString& str ) const {
-        return m_map.equal_range( str );
+        return m_map.equal_range( HashedString(str) );
     }
-    
+
+    ///If the list has more then size items, the first items are removed until the \
size fits. +    void limitSize( int size );
+  
     void removeAllItems( const QString& str );
     
     bool hasItem( const QString& str ) const {
-        Map::const_iterator it = m_map.find( str );
+        Map::const_iterator it = m_map.find( HashedString(str) );
         return it != m_map.end();
     }
 private:
+    int m_insertionNumber;
     Map m_map;
+    typedef __gnu_cxx::hash_map<HashedString, int> InsertionMap;
+  InsertionMap m_insertionNumbers; //This is used to count which file was inserted \
first(higher insertion-number -> inserted later)  KListView* m_list;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic