[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master babfb064c4 1/2: Make string-pixel-width slightly speedier
From: |
Lars Ingebrigtsen |
Subject: |
master babfb064c4 1/2: Make string-pixel-width slightly speedier |
Date: |
Sat, 19 Feb 2022 08:21:28 -0500 (EST) |
branch: master
commit babfb064c48e621ab7ad43b380ed1fdb0a6904a8
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
lisp/emacs-lisp/subr-x.el | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 1f69850958..647397e7f7 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)