]> git.eshelyaron.com Git - emacs.git/commitdiff
Speed up shr-string-pixel-width
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 17 Jun 2022 11:48:53 +0000 (13:48 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 17 Jun 2022 11:49:10 +0000 (13:49 +0200)
* lisp/net/eww.el (eww-update-header-line-format): Use
string-pixel-width (since we don't care about shr-use-fonts here).
* lisp/net/shr.el (shr-string-pixel-width): Use
`string-pixel-width', which should be faster.

lisp/net/eww.el
lisp/net/shr.el

index 8f02be12ff839bca4cd03a333dca9856d3af8857..3c16942e7c01caac4a936183feea3a998faee727 100644 (file)
@@ -833,7 +833,7 @@ The renaming scheme is performed in accordance with
                (when url
                  (setq url (propertize url 'face 'variable-pitch))
                  (let* ((parsed (url-generic-parse-url url))
-                        (host-length (shr-string-pixel-width
+                        (host-length (string-pixel-width
                                       (propertize
                                        (format "%s://%s" (url-type parsed)
                                                (url-host parsed))
@@ -842,17 +842,17 @@ The renaming scheme is performed in accordance with
                    (cond
                     ;; The host bit is wider than the window, so nix
                     ;; the title.
-                    ((> (+ host-length (shr-string-pixel-width "xxxxx")) width)
+                    ((> (+ host-length (string-pixel-width "xxxxx")) width)
                      (setq title ""))
                     ;; Trim the title.
-                    ((> (+ (shr-string-pixel-width (concat title "xx"))
+                    ((> (+ (string-pixel-width (concat title "xx"))
                            host-length)
                         width)
                      (setq title
                            (concat
                             (eww--limit-string-pixelwise
                              title (- width host-length
-                                      (shr-string-pixel-width
+                                      (string-pixel-width
                                        (propertize "...: " 'face
                                                    'variable-pitch))))
                             (propertize "..." 'face 'variable-pitch)))))))
index b54144576ef17466378f0d2fde85174d5b866501..b269607e323203c7e690eb9fe062fc24c9a4a1b9 100644 (file)
@@ -337,6 +337,11 @@ and other things:
            0))
     (pixel-fill-width)))
 
+(defmacro shr-string-pixel-width (string)
+  `(if (not shr-use-fonts)
+       (length ,string)
+     (string-pixel-width ,string)))
+
 ;;;###autoload
 (defun shr-insert-document (dom)
   "Render the parsed document DOM into the current buffer.
@@ -677,19 +682,6 @@ size, and full-buffer size."
        (goto-char (mark))
        (shr-pixel-column))))
 
-(defun shr-string-pixel-width (string)
-  (if (not shr-use-fonts)
-      (length string)
-    ;; Save and restore point across with-temp-buffer, since
-    ;; shr-pixel-column uses save-window-excursion, which can reset
-    ;; point to 1.
-    (let ((pt (point)))
-      (prog1
-         (with-temp-buffer
-           (insert string)
-           (shr-pixel-column))
-       (goto-char pt)))))
-
 (defsubst shr--translate-insertion-chars ()
   ;; Remove soft hyphens.
   (goto-char (point-min))