help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to get plist properties list?


From: Stefan Monnier
Subject: Re: How to get plist properties list?
Date: Fri, 08 Jan 2021 00:20:59 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>     (dotimes (i length (reverse properties))
>       (if (divisible-by-2-or-0-p i)
>           (push (elt plist i) properties)))))

This is another example of a dotimes+elt loop, i.e. a loop where you
end up with an unwarranted O(n²) complexity (i.e. a performance bug).

>     (while (/= n (length plist))
>       (push (elt plist n) properties)
>       (setq n (+ 2 n)))
>     properties))

Same problem here.

> But maybe there is some more simpler way to get plist properties list?

Probably not the simplest but this should work:

    (defun plist-keys (plist)
      (let (keys iskey)
        (dolist (x plist)
          (if (setq iskey (not iskey)) (push x keys)))
        (nreverse keys)))

The simplest might be:

    (map-keys plist)


-- Stefan




reply via email to

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