[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] master 1691a51: * lisp/emacs-lisp/map.el: Make the fun

From: Basil L. Contovounesios
Subject: Re: [Emacs-diffs] master 1691a51: * lisp/emacs-lisp/map.el: Make the functions generic
Date: Thu, 13 Dec 2018 14:25:24 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

address@hidden (Stefan Monnier) writes:

> -(defun map-empty-p (map)
> +(cl-defgeneric map-empty-p (map)
>    "Return non-nil if MAP is empty.
> +The default implementation delegates to `map-length'."
> +  (zerop (map-length map)))
> -MAP can be a list, hash-table or array."
> -  (map--dispatch map
> -    :list (null map)
> -    :array (seq-empty-p map)
> -    :hash-table (zerop (hash-table-count map))))

Why not continue to check whether lists are null, rather than traversing
their entire length:

  (cl-defmethod map-empty-p ((map list))
    (null map))

Is it not worth it?

> +(cl-defmethod map-contains-key ((map list) key &optional testfn)
> +  (alist-get key map nil nil (or testfn #'equal)))

I think this should get the same treatment as the hash table method,
which checks whether DEFAULT was returned:

  (cl-defmethod map-contains-key ((map list) key &optional testfn)
    (let ((v '(nil)))
      (not (eq v (alist-get key map v nil (or testfn #'equal))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]