]> git.eshelyaron.com Git - emacs.git/commitdiff
Revert use of seq-count in shr-count
authorStefan Kangas <stefankangas@gmail.com>
Mon, 4 Sep 2023 19:28:33 +0000 (21:28 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Mon, 4 Sep 2023 19:28:33 +0000 (21:28 +0200)
* lisp/net/shr.el (shr-count): Prefer handwritten code to using
'seq-count', as it's more performant.
Problem reported by Mattias EngdegĂ„rd <mattiase@acm.org>.

lisp/net/shr.el

index 84033c31ef44d9f2bd237630b8a344b44ffdcfea..645e1cc51e52fbc62c9254749174df4dffdf9022 100644 (file)
@@ -2617,10 +2617,13 @@ flags that control whether to collect or render objects."
     columns))
 
 (defun shr-count (dom elem)
-  (seq-count (lambda (sub)
-               (and (not (stringp sub))
-                    (eq (dom-tag sub) elem)))
-             (dom-children dom)))
+  ;; This is faster than `seq-count', and shr can use it.
+  (let ((i 0))
+    (dolist (sub (dom-children dom))
+      (when (and (not (stringp sub))
+                 (eq (dom-tag sub) elem))
+        (setq i (1+ i))))
+    i))
 
 (defun shr-max-columns (dom)
   (let ((max 0)