Subject: Re: bug#51620: add-hook repeatedly adds same function into hook--depth-alist

From: Michael Heerdegen <[email-masked]>
Date: Sat, 06 Nov 2021 01:13:02 +0100

Filipp Gunbin <[email-masked]> writes:

> diff --git a/lisp/subr.el b/lisp/subr.el
> index 8ff403e113..2b8b6deeb0 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -1868,7 +1868,7 @@ add-hook
>        (when (or (get hook 'hook--depth-alist) (not (zerop depth)))
>          ;; Note: The main purpose of the above `when' test is to avoid running
>          ;; this `setf' before `gv' is loaded during bootstrap.
> -        (push (cons function depth) (get hook 'hook--depth-alist)))
> +        (setf (alist-get function (get hook 'hook--depth-alist) 0) depth))
>        (setq hook-value
>  	    (if (< 0 depth)
>  		(append hook-value (list function))

So the function would still be compared using `eq' but we would avoid to
add dups of equal conses?  Looks reasonable to me -- Stefan?

TIA,

Michael.