From: Lars Ingebrigtsen Date: Sat, 19 Feb 2022 13:20:30 +0000 (+0100) Subject: Make string-pixel-width slightly speedier X-Git-Tag: emacs-29.0.90~2229 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=babfb064c48e621ab7ad43b380ed1fdb0a6904a8;p=emacs.git 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. --- 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)