[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 82cc1f4fda1: Revert use of seq-count in shr-count
From: |
Philip Kaludercic |
Subject: |
Re: master 82cc1f4fda1: Revert use of seq-count in shr-count |
Date: |
Mon, 04 Sep 2023 20:54:25 +0000 |
Stefan Kangas <stefankangas@gmail.com> writes:
> branch: master
> commit 82cc1f4fda19a635cc29577a4da051cf3e062afe
> Author: Stefan Kangas <stefankangas@gmail.com>
> Commit: Stefan Kangas <stefankangas@gmail.com>
>
> Revert use of seq-count in shr-count
>
> * 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>.
With seq becoming more and more popular, is there any conceivable way of
making it faster as well? The overhead of generic functional-call
dispatching always has me weary of using the library, or at the very
least has me think about it twice as it is convenient. Is there some
way to use the type inference that native compilation appears to provide
to statically determine what implementation to use?
> ---
> lisp/net/shr.el | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/net/shr.el b/lisp/net/shr.el
> index 84033c31ef4..645e1cc51e5 100644
> --- a/lisp/net/shr.el
> +++ b/lisp/net/shr.el
> @@ -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)
- Re: master 82cc1f4fda1: Revert use of seq-count in shr-count,
Philip Kaludercic <=