[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master d45fd91: * lisp/subr.el (delete-dups): Pre-size the
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] master d45fd91: * lisp/subr.el (delete-dups): Pre-size the hashtable. |
Date: |
Thu, 07 May 2015 01:14:02 +0000 |
branch: master
commit d45fd912eb7b90ce552db722dbe5893915f0fa1b
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
* lisp/subr.el (delete-dups): Pre-size the hashtable.
---
lisp/subr.el | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index ce9b44c..9c56e51 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -417,21 +417,21 @@ 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."
- (if (> (length list) 100)
- (let ((hash (make-hash-table :test #'equal))
- (tail list)
- elt retail)
- (puthash (car list) t hash)
- (while (setq retail (cdr tail))
- (setq elt (car retail))
- (if (gethash elt hash)
- (setcdr tail (cdr retail))
- (puthash elt t hash))
- (setq tail retail)))
- (let ((tail list))
- (while tail
- (setcdr tail (delete (car tail) (cdr tail)))
- (setq tail (cdr tail)))))
+ (let ((l (length list)))
+ (if (> l 100)
+ (let ((hash (make-hash-table :test #'equal :size l))
+ (tail list) retail)
+ (puthash (car list) t hash)
+ (while (setq retail (cdr tail))
+ (let ((elt (car retail)))
+ (if (gethash elt hash)
+ (setcdr tail (cdr retail))
+ (puthash elt t hash)))
+ (setq tail retail)))
+ (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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master d45fd91: * lisp/subr.el (delete-dups): Pre-size the hashtable.,
Stefan Monnier <=