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

List:       kde-core-devel
Subject:    Re: KDE fragile?
From:       Michael Matz <matz () ifh ! de>
Date:       2000-09-11 23:34:21
[Download RAW message or body]

Hi,

On Tue, 12 Sep 2000, Dirk Mueller wrote:
> Moin Michael!

interesting greeting line, esp. considering the real time ;)

> > fontpath (or fonts therein) changed. Hmm, and then the changed info is
> > propagated to every started application. Dunno.
> 
> I don't think using ksycoca is a good idea for font stuff. all we need to do
> is making kcharset faster... querying the X server is a lot faster than

I've seen some dog slow font-server serving old Tektronix
X-Terminals. Believe me, evrything is faster (on them) than parsing the
whole font list ;) Although, generally I agree.

Anyway, does the attached patch (moving all the while(i<CHARSETS_COUNT)
loops into QMaps) make a difference? (Review it careful, I did not test it
much, esp. not the charsets aspects)


Ciao,
Michael.

["kcharsets.diff" (TEXT/PLAIN)]

Index: kcharsets.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kcharsets.cpp,v
retrieving revision 1.76
diff -u -r1.76 kcharsets.cpp
--- kcharsets.cpp	2000/09/11 18:59:00	1.76
+++ kcharsets.cpp	2000/09/11 23:29:30
@@ -184,12 +184,13 @@
 	//kdDebug() << "KCharsetsPrivate::getAvailableCharsets " << *it << " " << family \
                <<endl;
         for ( QStringList::Iterator ch = chSets.begin(); ch != chSets.end(); ++ch ) \
                {
 	    //kdDebug() << "KCharsetsPrivate::getAvailableCharsets " << *ch << " " << \
                charsets->xNameToID( *ch ) << endl;
-            if( !availableCharsets->contains( charsets->xNameToID( *ch ) ) ) {
+	    QFont::CharSet id = charsets->xNameToID( *ch );
+            if( !availableCharsets->contains( id ) ) {
                 QStringList strList;
                 strList.append( family );
-                availableCharsets->insert( charsets->xNameToID( *ch ), strList );
+                availableCharsets->insert( id, strList );
             } else
-                ((*availableCharsets)[charsets->xNameToID( *ch )]).append(family);
+                ((*availableCharsets)[id]).append(family);
         }
     }
 
@@ -527,25 +528,50 @@
     return "*-*";
 }
 
+
+static QMap<QString, QFont::CharSet> *xname2id = 0;
+static QMap<QFont::CharSet, QString> *chset2name = 0;
+static QMap<QString, QFont::CharSet> *name2id = 0;
+
+static void cleanup_xNames()
+{ 
+    if (xname2id) delete xname2id;
+    if (name2id) delete name2id;
+    if (chset2name) delete chset2name;
+    xname2id = 0;
+    name2id = 0;
+    chset2name = 0;
+}
+
+static void setup_xNames()
+{
+    int i;
+    if (xname2id || chset2name || name2id) return;
+    xname2id = new QMap<QString, QFont::CharSet>;
+    name2id = new QMap<QString, QFont::CharSet>;
+    chset2name = new QMap<QFont::CharSet, QString>;
+    qAddPostRoutine( cleanup_xNames );
+    for (i=0; i < CHARSETS_COUNT; i++) {
+        QString n = xNames[i];
+	QString cs = charsetsStr[i];
+	xname2id->insert( n, charsetsIds[i] );
+	name2id->insert( cs, charsetsIds[i] );
+	chset2name->insert( charsetsIds[i], cs );
+    }
+}
+
 QFont::CharSet KCharsets::nameToID(QString name) const
 {
     name = name.lower();
 
-    int i = 0;
-    while(i < CHARSETS_COUNT)
-    {
-        if( name == charsetsStr[i] )
-            return charsetsIds[i];
-        i++;
-    }
-
-    i = 0;
-    while(i < CHARSETS_COUNT)
-    {
-        if( name == xNames[i] )
-            return charsetsIds[i];
-        i++;
-    }
+    if (!xname2id) setup_xNames();
+    
+    if (name2id->contains(name))
+        return (*name2id)[name];
+
+    if (xname2id->contains(name))
+        return (*xname2id)[name];
+    
     return QFont::AnyCharSet;
 }
 
@@ -558,14 +584,11 @@
 
 QString KCharsets::name(QFont::CharSet c)
 {
-    int i = 0;
+    if (!chset2name) setup_xNames();
 
-    while(i < CHARSETS_COUNT)
-    {
-        if( c == charsetsIds[i] )
-            return charsetsStr[i];
-        i++;
-    }
+    if (chset2name->contains(c))
+        return (*chset2name)[c];
+
     return "any";
 }
 
@@ -574,13 +597,11 @@
 {
     name = name.lower();
 
-    int i = 0;
-    while(i < CHARSETS_COUNT)
-    {
-       if( name == xNames[i] )
-            return charsetsIds[i];
-        i++;
-    }
+    if (!xname2id) setup_xNames();
+
+    if (xname2id->contains(name))
+        return (*xname2id)[name];
+
     return QFont::AnyCharSet;
 }
 



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

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