[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d710b84225 1/3: Make string-pixel-width about 40% faster
From: |
Lars Ingebrigtsen |
Subject: |
master d710b84225 1/3: Make string-pixel-width about 40% faster |
Date: |
Sun, 20 Feb 2022 10:14:11 -0500 (EST) |
branch: master
commit d710b8422547cf7c0e222408a2ca660cd6ce40b6
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Make string-pixel-width about 40% faster
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up.
---
lisp/emacs-lisp/subr-x.el | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 647397e7f7..7ad4e9ba2a 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)))))