From: Lars Ingebrigtsen Date: Tue, 3 May 2022 16:46:05 +0000 (+0200) Subject: Make tool bar caching more sensible X-Git-Tag: emacs-29.0.90~1931^2~96 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=99fbf39d61bf5e3d9618eafced92c2284938632d;p=emacs.git Make tool bar caching more sensible * lisp/tool-bar.el (tool-bar-keymap-cache): Make into a non-weak EQ hash table, which should be faster and not lose the contents after a GC (bug#43397). (tool-bar--flush-cache, tool-bar-make-keymap): Use the terminal only as the key. (tool-bar-local-item, tool-bar-local-item-from-menu): Flush the cache after altering the tool bar. --- diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el index 1271d1de23b..490fd0d3325 100644 --- a/lisp/tool-bar.el +++ b/lisp/tool-bar.el @@ -89,19 +89,18 @@ functions.") (declare-function image-mask-p "image.c" (spec &optional frame)) -(defconst tool-bar-keymap-cache (make-hash-table :weakness t :test 'equal)) +(defconst tool-bar-keymap-cache (make-hash-table)) (defun tool-bar--flush-cache () - (setf (gethash (cons (frame-terminal) tool-bar-map) tool-bar-keymap-cache) - nil)) + (setf (gethash (frame-terminal) tool-bar-keymap-cache) nil)) (defun tool-bar-make-keymap (&optional _ignore) "Generate an actual keymap from `tool-bar-map'. Its main job is to figure out which images to use based on the display's color capability and based on the available image libraries." - (let ((key (cons (frame-terminal) tool-bar-map))) - (or (gethash key tool-bar-keymap-cache) - (puthash key (tool-bar-make-keymap-1) tool-bar-keymap-cache)))) + (or (gethash (frame-terminal) tool-bar-keymap-cache) + (setf (gethash (frame-terminal) tool-bar-keymap-cache) + (tool-bar-make-keymap-1)))) (defun tool-bar-make-keymap-1 () "Generate an actual keymap from `tool-bar-map', without caching." @@ -182,6 +181,7 @@ ICON.xbm, using `find-image'." (let* ((image-exp (tool-bar--image-expression icon))) (define-key-after map (vector key) `(menu-item ,(symbol-name key) ,def :image ,image-exp ,@props)) + (tool-bar--flush-cache) (force-mode-line-update))) ;;;###autoload @@ -248,6 +248,7 @@ holds a keymap." (setq rest (cdr rest))) (append `(menu-item ,(car defn) ,rest) (list :image image-exp) props)))) + (tool-bar--flush-cache) (force-mode-line-update)))) ;;; Set up some global items. Additions/deletions up for grabs.