mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
Cache toolbar icon data paths
* lisp/image.el (find-image): Add an optional CACHE parameter. (find-image--cache): New variable. * lisp/tool-bar.el (tool-bar--image-expression): Use cached data to avoid looking up the image files on each refresh.
This commit is contained in:
parent
19c0afd0ad
commit
ab4b90723e
2 changed files with 29 additions and 19 deletions
|
|
@ -679,8 +679,10 @@ BUFFER nil or omitted means use the current buffer."
|
|||
(setq path (cdr path)))
|
||||
(if found filename)))
|
||||
|
||||
(defvar find-image--cache (make-hash-table :test #'equal))
|
||||
|
||||
;;;###autoload
|
||||
(defun find-image (specs)
|
||||
(defun find-image (specs &optional cache)
|
||||
"Find an image, choosing one of a list of image specifications.
|
||||
|
||||
SPECS is a list of image specifications.
|
||||
|
|
@ -695,26 +697,33 @@ is supported, and FILE exists, is used to construct the image
|
|||
specification to be returned. Return nil if no specification is
|
||||
satisfied.
|
||||
|
||||
If CACHE is non-nil, results are cached and returned on subsequent calls.
|
||||
|
||||
The image is looked for in `image-load-path'.
|
||||
|
||||
Image files should not be larger than specified by `max-image-size'."
|
||||
(let (image)
|
||||
(while (and specs (null image))
|
||||
(let* ((spec (car specs))
|
||||
(type (plist-get spec :type))
|
||||
(data (plist-get spec :data))
|
||||
(file (plist-get spec :file))
|
||||
found)
|
||||
(when (image-type-available-p type)
|
||||
(cond ((stringp file)
|
||||
(if (setq found (image-search-load-path file))
|
||||
(setq image
|
||||
(cons 'image (plist-put (copy-sequence spec)
|
||||
:file found)))))
|
||||
((not (null data))
|
||||
(setq image (cons 'image spec)))))
|
||||
(setq specs (cdr specs))))
|
||||
image))
|
||||
(or (and cache
|
||||
(gethash specs find-image--cache))
|
||||
(let ((orig-specs specs)
|
||||
image)
|
||||
(while (and specs (null image))
|
||||
(let* ((spec (car specs))
|
||||
(type (plist-get spec :type))
|
||||
(data (plist-get spec :data))
|
||||
(file (plist-get spec :file))
|
||||
found)
|
||||
(when (image-type-available-p type)
|
||||
(cond ((stringp file)
|
||||
(if (setq found (image-search-load-path file))
|
||||
(setq image
|
||||
(cons 'image (plist-put (copy-sequence spec)
|
||||
:file found)))))
|
||||
((not (null data))
|
||||
(setq image (cons 'image spec)))))
|
||||
(setq specs (cdr specs))))
|
||||
(when cache
|
||||
(setf (gethash orig-specs find-image--cache) image))
|
||||
image)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
|
|
|
|||
|
|
@ -159,7 +159,8 @@ To define items in any other map, use `tool-bar-local-item'."
|
|||
((< (display-color-cells) 256)
|
||||
',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
|
||||
(t
|
||||
',(list xpm-spec pbm-spec xbm-spec))))))
|
||||
',(list xpm-spec pbm-spec xbm-spec)))
|
||||
t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun tool-bar-local-item (icon def key map &rest props)
|
||||
|
|
|
|||
Loading…
Reference in a new issue