lisp/subr.el (delete-dups): Use a hash table
* lisp/subr.el (delete-dups): When there are more than 100 candidates, use a hash table. This can result in ~500 times speed-up for typical collections of size 5000, like that of `load-library'.
This commit is contained in:
parent
2fa7c314a5
commit
1f052a5f26
1 changed files with 13 additions and 5 deletions
18
lisp/subr.el
18
lisp/subr.el
|
@ -417,11 +417,19 @@ If N is omitted or nil, remove the last element."
|
|||
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
|
||||
(setcdr tail (delete (car tail) (cdr tail)))
|
||||
(setq tail (cdr tail))))
|
||||
list)
|
||||
(if (> (length list) 100)
|
||||
(let ((hash (make-hash-table :test #'equal))
|
||||
res)
|
||||
(dolist (elt list)
|
||||
(unless (gethash elt hash)
|
||||
(puthash elt elt hash)
|
||||
(push elt res)))
|
||||
(nreverse res))
|
||||
(let ((tail list))
|
||||
(while tail
|
||||
(setcdr tail (delete (car tail) (cdr tail)))
|
||||
(setq tail (cdr tail))))
|
||||
list))
|
||||
|
||||
;; See http://lists.gnu.org/archive/html/emacs-devel/2013-05/msg00204.html
|
||||
(defun delete-consecutive-dups (list &optional circular)
|
||||
|
|
Loading…
Add table
Reference in a new issue