diff options
| author | Stefan Monnier | 2015-05-06 21:13:56 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-05-06 21:13:56 -0400 |
| commit | d45fd912eb7b90ce552db722dbe5893915f0fa1b (patch) | |
| tree | 4add198e560389b38cb757309d04c4b7ab770767 | |
| parent | bceffdb3796df75b6f2efc2f6f17ca927a25c3b9 (diff) | |
| download | emacs-d45fd912eb7b90ce552db722dbe5893915f0fa1b.tar.gz emacs-d45fd912eb7b90ce552db722dbe5893915f0fa1b.zip | |
* lisp/subr.el (delete-dups): Pre-size the hashtable.
| -rw-r--r-- | lisp/subr.el | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index ce9b44c6ef9..9c56e51bc96 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -417,21 +417,21 @@ If N is omitted or nil, remove the last element." | |||
| 417 | Store the result in LIST and return it. LIST must be a proper list. | 417 | Store the result in LIST and return it. LIST must be a proper list. |
| 418 | Of several `equal' occurrences of an element in LIST, the first | 418 | Of several `equal' occurrences of an element in LIST, the first |
| 419 | one is kept." | 419 | one is kept." |
| 420 | (if (> (length list) 100) | 420 | (let ((l (length list))) |
| 421 | (let ((hash (make-hash-table :test #'equal)) | 421 | (if (> l 100) |
| 422 | (tail list) | 422 | (let ((hash (make-hash-table :test #'equal :size l)) |
| 423 | elt retail) | 423 | (tail list) retail) |
| 424 | (puthash (car list) t hash) | 424 | (puthash (car list) t hash) |
| 425 | (while (setq retail (cdr tail)) | 425 | (while (setq retail (cdr tail)) |
| 426 | (setq elt (car retail)) | 426 | (let ((elt (car retail))) |
| 427 | (if (gethash elt hash) | 427 | (if (gethash elt hash) |
| 428 | (setcdr tail (cdr retail)) | 428 | (setcdr tail (cdr retail)) |
| 429 | (puthash elt t hash)) | 429 | (puthash elt t hash))) |
| 430 | (setq tail retail))) | 430 | (setq tail retail))) |
| 431 | (let ((tail list)) | 431 | (let ((tail list)) |
| 432 | (while tail | 432 | (while tail |
| 433 | (setcdr tail (delete (car tail) (cdr tail))) | 433 | (setcdr tail (delete (car tail) (cdr tail))) |
| 434 | (setq tail (cdr tail))))) | 434 | (setq tail (cdr tail)))))) |
| 435 | list) | 435 | list) |
| 436 | 436 | ||
| 437 | ;; See http://lists.gnu.org/archive/html/emacs-devel/2013-05/msg00204.html | 437 | ;; See http://lists.gnu.org/archive/html/emacs-devel/2013-05/msg00204.html |