diff options
| author | Juri Linkov | 2025-07-09 09:32:18 +0300 |
|---|---|---|
| committer | Juri Linkov | 2025-07-09 09:32:18 +0300 |
| commit | c4674bfa3ae830eedf3d1c2b27fe623e11e7fb25 (patch) | |
| tree | a7276a9a378cfca03aa70d033889b7f3bb69a4b5 | |
| parent | 8b1978fa6e929101b6a766cfbb94c3b27b142fa7 (diff) | |
| download | emacs-c4674bfa3ae830eedf3d1c2b27fe623e11e7fb25.tar.gz emacs-c4674bfa3ae830eedf3d1c2b27fe623e11e7fb25.zip | |
Cache 'string-pixel-width' in 'tab-bar-format-align-right' (bug#78953)
* lisp/tab-bar.el (tab-bar--align-right-hash): New internal variable.
(tab-bar-format-align-right): Use memoization for 'string-pixel-width'.
| -rw-r--r-- | lisp/tab-bar.el | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 0ed372de176..6a86962476e 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -1194,19 +1194,29 @@ when the tab is current. Return the result as a keymap." | |||
| 1194 | `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab | 1194 | `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab |
| 1195 | :help "New tab")))) | 1195 | :help "New tab")))) |
| 1196 | 1196 | ||
| 1197 | (defvar tab-bar--align-right-hash nil | ||
| 1198 | "Memoization table for `tab-bar-format-align-right'.") | ||
| 1199 | |||
| 1197 | (defun tab-bar-format-align-right (&optional rest) | 1200 | (defun tab-bar-format-align-right (&optional rest) |
| 1198 | "Align the rest of tab bar items to the right. | 1201 | "Align the rest of tab bar items to the right. |
| 1199 | The argument `rest' is used for special handling of this item | 1202 | The argument `rest' is used for special handling of this item |
| 1200 | by `tab-bar-format-list' that collects the rest of formatted items. | 1203 | by `tab-bar-format-list' that collects the rest of formatted items. |
| 1201 | This prevents calling other non-idempotent items like | 1204 | This prevents calling other non-idempotent items like |
| 1202 | `tab-bar-format-global' twice." | 1205 | `tab-bar-format-global' twice." |
| 1206 | (unless tab-bar--align-right-hash | ||
| 1207 | (define-hash-table-test 'tab-bar--align-right-hash-test | ||
| 1208 | #'equal-including-properties | ||
| 1209 | #'sxhash-equal-including-properties) | ||
| 1210 | (setq tab-bar--align-right-hash | ||
| 1211 | (make-hash-table :test 'tab-bar--align-right-hash-test))) | ||
| 1203 | (let* ((rest (or rest (tab-bar-format-list | 1212 | (let* ((rest (or rest (tab-bar-format-list |
| 1204 | (cdr (memq 'tab-bar-format-align-right | 1213 | (cdr (memq 'tab-bar-format-align-right |
| 1205 | tab-bar-format))))) | 1214 | tab-bar-format))))) |
| 1206 | (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) | 1215 | (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) |
| 1207 | (hpos (progn | 1216 | (hpos (progn |
| 1208 | (add-face-text-property 0 (length rest) 'tab-bar t rest) | 1217 | (add-face-text-property 0 (length rest) 'tab-bar t rest) |
| 1209 | (string-pixel-width rest))) | 1218 | (with-memoization (gethash rest tab-bar--align-right-hash) |
| 1219 | (string-pixel-width rest)))) | ||
| 1210 | (str (propertize " " 'display | 1220 | (str (propertize " " 'display |
| 1211 | ;; The `right' spec doesn't work on TTY frames | 1221 | ;; The `right' spec doesn't work on TTY frames |
| 1212 | ;; when windows are split horizontally (bug#59620) | 1222 | ;; when windows are split horizontally (bug#59620) |