GNU bug report logs - #27584
26.0.50; alist-get: Add optional arg TESTFN

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Wed, 5 Jul 2017 03:24:02 UTC

Severity: wishlist

Found in version 26.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Nicolas Petton <nicolas <at> petton.fr>
To: Tino Calancha <tino.calancha <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: Tino Calancha <tino.calancha <at> gmail.com>, monnier <at> iro.umontreal.ca, 27584 <at> debbugs.gnu.org
Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Sat, 08 Jul 2017 13:29:20 +0200
[Message part 1 (text/plain, inline)]
Tino Calancha <tino.calancha <at> gmail.com> writes:

> Do you mean something like this?
>
> {
>    Lisp_Object tail = list;
>    Lisp_Object fn = NILP (testfn) ? Qequal : testfn;
>      FOR_EACH_TAIL (tail)
>        {
>          Lisp_Object car = XCAR (tail);
>          if (CONSP (car) && !NILP (call2 (fn, (XCAR (car)), key)))
>            return car;
>        }
>
>    CHECK_LIST_END (tail, list);
>    return Qnil;
> }
>
> ;; This is shorter but now the default case, because the call2, is less 
> ;; efficient than just using Fequal, right?

I like your version more, but I also thought that it would be slower for
the default case.

I ran benchmark-run with the first version:

  (setq alist (mapcar (lambda (e) `(,(intern e) . ,e))
                      (locate-file-completion-table
       	               load-path (get-load-suffixes) "" nil t)))
      
  (benchmark-run (assoc 'absent alist))
  (0.00023356 0 0.0)
  (0.00016584 0 0.0)
  (0.000165243 0 0.0)
  (0.000164741 0 0.0)
  (0.000240754 0 0.0)
  (0.000104102 0 0.0)

and with your version:

  (0.000556587 0 0.0)
  (0.000238677 0 0.0)
  (0.000498506 0 0.0)
  (0.000527675 0 0.0)
  (0.00064989 0 0.0)
  (0.000520543 0 0.0)

Cheers,
Nico
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 7 years and 352 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.