summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleh Krehel <ohwoeowho@gmail.com>2015-05-06 15:21:23 +0200
committerOleh Krehel <ohwoeowho@gmail.com>2015-05-06 15:52:06 +0200
commit1f052a5f26250d726618570a816ddb6fd0cc11a0 (patch)
treefd1738c6587bf152df95702ece24a1e6c204df3f
parent2fa7c314a52c8d1cb29a893341d1c03e8ede57cd (diff)
downloademacs-1f052a5f26250d726618570a816ddb6fd0cc11a0.tar.gz
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'.
-rw-r--r--lisp/subr.el18
1 files changed, 13 insertions, 5 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 0fec29c1404..591980d03fa 100644
--- a/lisp/subr.el
+++ b/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)