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

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/io
From:       Matthias Kretz <kretz () kde ! org>
Date:       2007-01-31 22:20:53
Message-ID: 1170282053.711495.9477.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 628912 by mkretz:

remove another KStaticDeleter by moving the cache into the other private.
Also the cache was storing the number and area name, even though the
name was already stored as the key in the hash, so I removed the former.


 M  +57 -80    kdebug.cpp  


--- trunk/KDE/kdelibs/kdecore/io/kdebug.cpp #628911:628912
@@ -64,86 +64,8 @@
 
 #include "kdebugdbusiface_p.h"
 
-struct KDebugEntry
-{
-    KDebugEntry (unsigned int n = 0, const QByteArray& d = QByteArray()) {number=n; descr=d;}
-    unsigned int number;
-    QByteArray descr;
-};
-
-typedef QHash<unsigned int, KDebugEntry> debug_cache;
-static debug_cache *KDebugCache;
-
 KDECORE_EXPORT bool kde_kdebug_enable_dbus_interface = false;
 
-static KStaticDeleter< debug_cache > kdd;
-
-static QByteArray getDescrFromNum(unsigned int _num)
-{
-  if (!KDebugCache) {
-    kdd.setObject(KDebugCache, new debug_cache);
-    // Do not call this deleter from ~KApplication
-    KGlobal::unregisterStaticDeleter(&kdd);
-  }
-
-  if ( KDebugCache->contains( _num ) )
-    return KDebugCache->value( _num ).descr;
-
-  if ( !KDebugCache->isEmpty() ) // areas already loaded
-    return QByteArray();
-
-  QString filename(KStandardDirs::locate("config", QLatin1String("kdebug.areas")));
-  if (filename.isEmpty())
-      return QByteArray();
-
-  QFile file(filename);
-  if (!file.open(QIODevice::ReadOnly)) {
-    qWarning("Couldn't open %s", filename.toLocal8Bit().constData());
-    file.close();
-    return QByteArray();
-  }
-
-  uint lineNumber=0;
-  QByteArray line(1024, 0);
-  int len;
-
-  while (( len = file.readLine(line.data(),line.size()-1) ) > 0) {
-      int i=0;
-      ++lineNumber;
-
-      while (line[i] && line[i] <= ' ')
-        i++;
-
-      unsigned char ch=line[i];
-
-      if ( !ch || ch =='#' || ch =='\n')
-          continue; // We have an eof, a comment or an empty line
-
-      if (ch < '0' && ch > '9') {
-          qWarning("Syntax error: no number (line %u)",lineNumber);
-          continue;
-      }
-
-      const int numStart=i;
-      do {
-          ch=line[++i];
-      } while ( ch >= '0' && ch <= '9');
-
-      unsigned int number = line.mid(numStart, i).toUInt(); // ###
-
-      while (line[i] && line[i] <= ' ')
-        i++;
-
-      KDebugCache->insert(number, KDebugEntry(number, line.mid(i, len-i-1)));
-  }
-  file.close();
-
-  if ( KDebugCache->contains( _num ) )
-      return KDebugCache->value( _num ).descr;
-
-  return QByteArray();
-}
-
 enum DebugLevels {
     KDEBUG_INFO=    0,
     KDEBUG_WARN=    1,
@@ -151,7 +73,6 @@
     KDEBUG_FATAL=   3
 };
 
-
 struct kDebugPrivate
 {
     kDebugPrivate()
@@ -182,10 +103,66 @@
         delete kDebugDBusIface;
     }
 
+    QByteArray getDescrFromNum(unsigned int num)
+    {
+        if (!cache.isEmpty()) { // areas already loaded
+            return cache.value(num);
+        }
+
+        QString filename(KStandardDirs::locate("config", QLatin1String("kdebug.areas")));
+        if (filename.isEmpty()) {
+            return QByteArray();
+        }
+        QFile file(filename);
+        if (!file.open(QIODevice::ReadOnly)) {
+            qWarning("Couldn't open %s", filename.toLocal8Bit().constData());
+            file.close();
+            return QByteArray();
+        }
+
+        uint lineNumber=0;
+        QByteArray line(1024, 0);
+        int len;
+
+        while ((len = file.readLine(line.data(),line.size()-1)) > 0) {
+            int i=0;
+            ++lineNumber;
+
+            while (line[i] && line[i] <= ' ')
+                i++;
+
+            unsigned char ch=line[i];
+
+            if (!ch || ch =='#' || ch =='\n')
+                continue; // We have an eof, a comment or an empty line
+
+            if (ch < '0' && ch > '9') {
+                qWarning("Syntax error: no number (line %u)",lineNumber);
+                continue;
+            }
+
+            const int numStart=i;
+            do {
+                ch=line[++i];
+            } while (ch >= '0' && ch <= '9');
+
+            unsigned int number = line.mid(numStart, i).toUInt(); // ###
+
+            while (line[i] && line[i] <= ' ')
+                i++;
+
+            cache.insert(number, line.mid(i, len-i-1));
+        }
+        file.close();
+
+        return cache.value(num);
+    }
+
     QByteArray aAreaName;
     unsigned int oldarea;
     KConfig *config;
     KDebugDBusIface *kDebugDBusIface;
+    QHash<unsigned int, QByteArray> cache;
 };
 
 K_GLOBAL_STATIC(kDebugPrivate, kDebug_data)
@@ -241,7 +218,7 @@
             kDebug_data->oldarea = nArea;
             if (KGlobal::hasMainComponent()) {
                 if (nArea > 0) {
-                    kDebug_data->aAreaName = getDescrFromNum(nArea);
+                    kDebug_data->aAreaName = kDebug_data->getDescrFromNum(nArea);
                 }
                 if ((nArea == 0) || kDebug_data->aAreaName.isEmpty()) {
                     kDebug_data->aAreaName = KGlobal::mainComponent().componentName();
[prev in list] [next in list] [prev in thread] [next in thread] 

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