diff options
author | forcer <forcer> | 2006-12-07 09:46:00 +0000 |
---|---|---|
committer | forcer <mwolson@gnu.org> | 2006-12-07 09:46:00 +0000 |
commit | 2adff3ed4e9dabb25680880df66b7e67b9f635bb (patch) | |
tree | 2adfe9cb15b6bd6d5e9c5b5157aa8f2e5bdce647 | |
parent | ea35b0637aff4d1f61dac2d25b6556a4d939e6b4 (diff) |
emms.el: Improve `emms-uniq-list' to not use cl.el.
darcs-hash:20061207094656-2189f-b0e45986b49ad8a3f15f50c57a80cf644608f428.gz
-rw-r--r-- | emms.el | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -1104,14 +1104,21 @@ ignore this." (emms-playlist-select pos) (emms-playlist-first))))) -(defun emms-uniq-list (list stringfy) +(defun emms-uniq-list (list stringify) "Compare stringfied element of list, and remove duplicate elements." - (let ((hash (make-hash-table :test 'equal)) - str) - (remove-if (lambda (elm) - (setq str (funcall stringfy elm)) - (if (gethash str hash) t - (puthash str t hash) nil)) list))) + ;; This uses a fast append list, keeping a pointer to the last cons + ;; cell of the list (TAIL). It might be worthwhile to provide an + ;; abstraction for this eventually. + (let* ((hash (make-hash-table :test 'equal)) + (result (cons nil nil)) + (tail result)) + (dolist (element list) + (let ((str (funcall stringify element))) + (when (not (gethash str hash)) + (setcdr tail (cons element nil)) + (setq tail (cdr tail))) + (puthash str t hash))) + (cdr result))) (defun emms-playlist-simple-uniq () "Remove duplicate tracks" |