Maintain a cache of the image directories.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Fri, 3 Sep 2010 23:57:39 +0000 (01:57 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Fri, 3 Sep 2010 23:57:39 +0000 (01:57 +0200)
This means that the `g' command in Gnus doesn't have to stat dozens of
directories each time.

lisp/ChangeLog
lisp/mm-util.el

index 45c798b..94fb680 100644 (file)
@@ -2,6 +2,9 @@
 
        * mm-util.el (mm-image-load-path): Just return the image directories,
        not all directories in the path in addition to the image directories.
+       (mm-image-load-path): Maintain a cache of the image directories so that
+       the `g' command in Gnus doesn't have to stat dozens of directories each
+       time. 
 
        * gnus-html.el (gnus-html-put-image): Allow images to be removed.
        (gnus-html-wash-tags): Add a new `i' command to insert images.
index 8808b0b..588915a 100644 (file)
@@ -1429,16 +1429,23 @@ If SUFFIX is non-nil, add that at the end of the file name."
        ;; Reset the umask.
        (set-default-file-modes umask)))))
 
+(defvar mm-image-load-path-cache nil)
+
 (defun mm-image-load-path (&optional package)
-  (let (dir result)
-    (dolist (path load-path)
-      (when (and path
-                (file-directory-p
-                 (setq dir (concat (file-name-directory
-                                    (directory-file-name path))
-                                   "etc/images/" (or package "gnus/")))))
-       (push dir result)))
-    (nreverse result)))
+  (if (and mm-image-load-path-cache
+          (equal load-path (car mm-image-load-path-cache)))
+      (cdr mm-image-load-path-cache)
+    (let (dir result)
+      (dolist (path load-path)
+       (when (and path
+                  (file-directory-p
+                   (setq dir (concat (file-name-directory
+                                      (directory-file-name path))
+                                     "etc/images/" (or package "gnus/")))))
+         (push dir result)))
+      (setq result (nreverse result)
+           mm-image-load-path-cache (cons load-path result))
+      result)))
 
 ;; Fixme: This doesn't look useful where it's used.
 (if (fboundp 'detect-coding-region)