summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-02-20 15:24:47 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-02-20 16:14:05 +0100
commitd710b8422547cf7c0e222408a2ca660cd6ce40b6 (patch)
treeccdb1b64ca86cb16074914f03487793e968e64b0 /lisp/emacs-lisp
parent277b49d7a3241fcba1391f7c200c1195dfa1900c (diff)
downloademacs-d710b8422547cf7c0e222408a2ca660cd6ce40b6.tar.gz
emacs-d710b8422547cf7c0e222408a2ca660cd6ce40b6.tar.bz2
emacs-d710b8422547cf7c0e222408a2ca660cd6ce40b6.zip
Make string-pixel-width about 40% faster
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/subr-x.el5
1 files changed, 4 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 647397e7f7b..7ad4e9ba2ab 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -446,7 +446,10 @@ is inserted before adjusting the number of empty lines."
"Return the width of STRING in pixels."
(if (zerop (length string))
0
- (with-temp-buffer
+ ;; Keeping a work buffer around is more efficient than creating a
+ ;; new temporary buffer.
+ (with-current-buffer (get-buffer-create " *string-pixel-width*")
+ (delete-region (point-min) (point-max))
(insert string)
(car (buffer-text-pixel-size nil nil t)))))