From 2adff3ed4e9dabb25680880df66b7e67b9f635bb Mon Sep 17 00:00:00 2001 From: forcer Date: Thu, 7 Dec 2006 09:46:00 +0000 Subject: emms.el: Improve `emms-uniq-list' to not use cl.el. darcs-hash:20061207094656-2189f-b0e45986b49ad8a3f15f50c57a80cf644608f428.gz --- emms.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/emms.el b/emms.el index 89c57ba..64bb93c 100644 --- a/emms.el +++ b/emms.el @@ -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" -- cgit v1.2.3