Skip to content
Snippets Groups Projects
Commit 048de2e5 authored by Attila Lendvai's avatar Attila Lendvai
Browse files

Optimize DELETE-FROM-PLIST not to cons.

Patch by "James M. Lawrence" <llmjjmll@gmail.com>
parent 1bb1d834
No related branches found
No related tags found
No related merge requests found
......@@ -278,8 +278,20 @@ not destructively modified. Keys are compared using EQ."
(defun delete-from-plist (plist &rest keys)
"Just like REMOVE-FROM-PLIST, but this version may destructively modify the
provided plist."
;; FIXME: should not cons
(apply 'remove-from-plist plist keys))
(declare (optimize speed))
(loop with head = plist
with tail = nil ; a nil tail means an empty result so far
for (key . rest) on plist by #'cddr
do (assert rest () "Expected a proper plist, got ~S" plist)
(if (member key keys :test #'eq)
;; skip over this pair
(symbol-macrolet ((next (cdr rest)))
(if tail
(setf (cdr tail) next)
(setf head next)))
;; keep this pair
(setf tail rest))
finally (return head)))
(define-modify-macro remove-from-plistf (&rest keys) remove-from-plist
"Modify macro for REMOVE-FROM-PLIST.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment