OoO La  nuit ayant déjà recouvert  d'encre ce jour du  mercredi 15 avril
2009, vers 23:37, Petr Gajdůšek <[email protected]> disait :

> I have added the line you suggested and looked at times.
> Lines that take too long to be processed are the lines without icon
> specification. I look through the code and find that array "icons" is
> filled with all system icons (take 2 seconds) and then this array is
> searched for icon with application's shortcommand in its name. And this
> searching is probably what makes things slow. Lines without icon
> specification take 0.3s, lines with icon specification take avarage
> 0.0007s.

> I have probably too much icons installed and too much menu entries with
> no icon specified.

> SYSTEM_ICONDIRS = [ "/usr/share/pixmaps", "/usr/share/icons" ]

> $ find /usr/share/pixmaps /usr/share/icons -name '*.png' -o -name
> '*.xpm' | wc -l
> 60815

Thanks for the hint!

Could you  try this  patch? I hope  it will  be more efficient  than the
original version.

diff --git a/debian/createmenu.py b/debian/createmenu.py
index 34f7432..5b6bcfd 100644
--- a/debian/createmenu.py
+++ b/debian/createmenu.py
@@ -29,6 +29,14 @@ import stat
 import getopt
 import subprocess
 
+def trans(char):
+    if char.isalnum():
+        return char
+    if char in ["-", "_", ".", "(", ")", ",", "+"]:
+        return char
+    return "_"
+transtable = "".join([trans(chr(x)) for x in range(0,256)])
+
 def remove(base):
     for top in [base, DM_ICONBASE]:
         for root, dirs, files in os.walk(top, topdown=False):
@@ -39,14 +47,7 @@ def remove(base):
 
 def install(base):
 
-    def trans(char):
-        if char.isalnum():
-            return char
-        if char in ["-", "_", ".", "(", ")", ",", "+"]:
-            return char
-        return "_"
-
-    icons = []
+    icons = {}
     noicons = []
     for l in open(os.path.join(base, "fvwm-crystal.debian-menu")).readlines():
         if l.startswith("#"):
@@ -57,7 +58,6 @@ def install(base):
             continue
 
         # Translate dangerous characters
-        transtable = "".join([trans(chr(x)) for x in range(0,256)])
         title = title.translate(transtable)
         shortcommand = command.split(" ")[0].split("/")[-1].translate(transtable)
 
@@ -104,17 +104,16 @@ def install(base):
         if not os.path.isfile(icon):
             # No icon has been provided, we need to find one
             if not icons:
-                # We build an array with all icons (only done one time)
+                # We build a dictionary with all icons (only done one time)
                 for bd in SYSTEM_ICONDIRS:
                     for root, dirs, files in os.walk(bd):
                         for name in files:
                             if name.endswith(".png") or name.endswith(".xpm"):
-                                icons.append(os.path.join(root, name))
-            match = [x for x in icons
-                     if x.lower().endswith("/%s.png" % shortcommand.lower()) or \
-                         x.lower().endswith("/%s.xpm" % shortcommand.lower()) ]
-            if match:
-                icon = match[0]
+                                m = name.lower()[:-4]
+                                if m not in icons or name.endswith(".png"):
+                                    icons[m] = os.path.join(root, name)
+            if shortcommand.lower() in icons:
+                icon = icons[shortcommand.lower()]
         if os.path.isfile(icon):
             # We have an icon, convert it
             for size in SIZES:
-- 
BOFH excuse  #317: Internet  exceeded Luser level,  please wait  until a
luser logs off before attempting to log back on.

Attachment: pgpjnTmk3nDsv.pgp
Description: PGP signature

Reply via email to