summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-02-19 14:20:30 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-02-19 14:21:19 +0100
commitbabfb064c48e621ab7ad43b380ed1fdb0a6904a8 (patch)
tree6671bc85ce6660cf30c86db763579b8cc1bd27f8 /lisp/emacs-lisp
parent14562b45bd81334064b19ed91f02e11cd46aaf56 (diff)
downloademacs-babfb064c48e621ab7ad43b380ed1fdb0a6904a8.tar.gz
emacs-babfb064c48e621ab7ad43b380ed1fdb0a6904a8.tar.bz2
emacs-babfb064c48e621ab7ad43b380ed1fdb0a6904a8.zip
Make string-pixel-width slightly speedier
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up string-pixel-width in the zero-length string case.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/subr-x.el8
1 files changed, 5 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 1f69850958c..647397e7f7b 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -444,9 +444,11 @@ is inserted before adjusting the number of empty lines."
;;;###autoload
(defun string-pixel-width (string)
"Return the width of STRING in pixels."
- (with-temp-buffer
- (insert string)
- (car (buffer-text-pixel-size nil nil t))))
+ (if (zerop (length string))
+ 0
+ (with-temp-buffer
+ (insert string)
+ (car (buffer-text-pixel-size nil nil t)))))
;;;###autoload
(defun string-glyph-split (string)