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

List:       kde-commits
Subject:    kdepim/kmail
From:       Till Adam <adam () kde ! org>
Date:       2004-03-29 21:56:35
Message-ID: 20040329215635.5BDA49953 () office ! kde ! org
[Download RAW message or body]

CVS commit by tilladam: 

Don't hardcode the size of the msgdict but gather intelligence as to the
total number of messages and store it in a secret config key and then
retrieve that on the next invocation of KMail and use it to initialize 
the dict size to nextPrime( lastSizeHint * 1.1 ).

The fancy math is due to I. Kloecker, who is reportedly good with numbers,
so I'll just take his word for it. ;)


  M +7 -0      kmail.kcfg   1.6
  M +26 -2     kmdict.cpp   1.5
  M +9 -1      kmmsgdict.cpp   1.34


--- kdepim/kmail/kmail.kcfg  #1.5:1.6
@@ -51,3 +51,10 @@
     </group>
 
+    <group name="General">
+      <entry name="MsgDictSizeHint" type="Int">
+        <default>9973</default>
+      </entry>
+    </group>
+
+
 </kcfg>

--- kdepim/kmail/kmdict.cpp  #1.4:1.5
@@ -7,12 +7,36 @@
 
 #include "kmdict.h"
+#include <kdebug.h>
 
 #include <string.h>
+#include <algorithm>
+
+// List of prime numbers shamelessly stolen from GCC STL
+enum { num_primes = 29 };
+
+static const unsigned long prime_list[ num_primes ] =
+{
+  31ul,        53ul,         97ul,         193ul,       389ul,
+  769ul,       1543ul,       3079ul,       6151ul,      12289ul,
+  24593ul,     49157ul,      98317ul,      196613ul,    393241ul,
+  786433ul,    1572869ul,    3145739ul,    6291469ul,   12582917ul,
+  25165843ul,  50331653ul,   100663319ul,  201326611ul, 402653189ul,
+  805306457ul, 1610612741ul, 3221225473ul, 4294967291ul
+};
+
+inline unsigned long nextPrime( unsigned long n )
+{
+  const unsigned long *first = prime_list;
+  const unsigned long *last = prime_list + num_primes;
+  const unsigned long *pos = std::lower_bound( first, last, n );
+  return pos == last ? *( last - 1 ) : *pos;
+}
 
 //-----------------------------------------------------------------------------
 
-KMDict::KMDict(int size)
+KMDict::KMDict( int size )
 {
-  init(size);
+  init( ( int ) nextPrime( size ) );
+  kdDebug( 5006 ) << "KMMDict::KMDict Size: " << mSize << endl;
 }
 

--- kdepim/kmail/kmmsgdict.cpp  #1.33:1.34
@@ -6,4 +6,5 @@
 #include "kmmsgdict.h"
 #include "kmdict.h"
+#include "globalsettings.h"
 
 #include <qfileinfo.h>
@@ -133,5 +135,8 @@ public:
 KMMsgDict::KMMsgDict()
 {
-  dict = new KMDict(9973);
+  int lastSizeOfDict = GlobalSettings::msgDictSizeHint();
+  lastSizeOfDict = ( lastSizeOfDict * 11 ) / 10;
+  GlobalSettings::setMsgDictSizeHint( 0 );
+  dict = new KMDict( lastSizeOfDict );
   nextMsgSerNum = 1;
 }
@@ -371,4 +376,7 @@ int KMMsgDict::readFolderIds(KMFolder *f
     rentry->set(index, entry);
   }
+  // Remember how many items we put into the dict this time so we can create 
+  // it with an appropriate size next time.
+  GlobalSettings::setMsgDictSizeHint( GlobalSettings::msgDictSizeHint() + count );
 
   fclose(fp);


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

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