projects
/
emacs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
277b49d
)
Make string-pixel-width about 40% faster
author
Lars Ingebrigtsen
<larsi@gnus.org>
Sun, 20 Feb 2022 14:24:47 +0000
(15:24 +0100)
committer
Lars Ingebrigtsen
<larsi@gnus.org>
Sun, 20 Feb 2022 15:14:05 +0000
(16:14 +0100)
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up.
lisp/emacs-lisp/subr-x.el
patch
|
blob
|
history
diff --git
a/lisp/emacs-lisp/subr-x.el
b/lisp/emacs-lisp/subr-x.el
index 647397e7f7b37b32dec97b5a9ee8d041cb038d3a..7ad4e9ba2ab192f8ac8878dfb20c4ad520df75ef 100644
(file)
--- 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)))))