]> git.eshelyaron.com Git - emacs.git/commitdiff
Make tool bar caching more sensible
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 3 May 2022 16:46:05 +0000 (18:46 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 3 May 2022 16:46:13 +0000 (18:46 +0200)
* 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.

lisp/tool-bar.el

index 1271d1de23be81dd69a6d0c6ef1b6999d05bd39d..490fd0d3325cf0936318a7b22383594facfc3d23 100644 (file)
@@ -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.