]> git.eshelyaron.com Git - emacs.git/commitdiff
(delete-dups): A better implementation from Karl Heuer <kwzh@gnu.org>.
authorEli Zaretskii <eliz@is.elta.co.il>
Mon, 16 Feb 2004 19:40:07 +0000 (19:40 +0000)
committerEli Zaretskii <eliz@is.elta.co.il>
Mon, 16 Feb 2004 19:40:07 +0000 (19:40 +0000)
lisp/subr.el

index 641d81a6fb612f5d5a3bd90da46d6fccdd28fb2c..0b3c3df4e8d49a98202b1f5e9e707641b699d567 100644 (file)
@@ -210,18 +210,14 @@ If N is bigger than the length of X, return X."
           x))))
 
 (defun delete-dups (list)
-  "Destructively return LIST, with `equal' duplicates removed.
-LIST must be a proper list.  The value of LIST after a call to
-this function is undefined.  Use \(setq LIST (delete-dups LIST))
-if you want to store the return value in LIST.  Of several
-`equal' occurrences of an element in LIST, the last one is kept."
-  (while (member (car list) (cdr list))
-    (pop list))
+  "Destructively remove `equal' duplicates from LIST.
+Store the result in LIST and return it.  LIST must be a proper list.
+Of several `equal' occurrences of an element in LIST, the first
+one is kept."
   (let ((tail list))
     (while tail
-      (while (member (cadr tail) (cddr tail))
-       (setcdr tail (cddr tail)))
-      (pop tail)))
+      (setcdr tail (delete (car tail) (cdr tail)))
+      (setq tail (cdr tail))))
   list)
 
 (defun number-sequence (from &optional to inc)