266 |
(defun gnus-registry-trim (alist) |
(defun gnus-registry-trim (alist) |
267 |
"Trim alist to size, using gnus-registry-max-entries." |
"Trim alist to size, using gnus-registry-max-entries." |
268 |
(if (null gnus-registry-max-entries) |
(if (null gnus-registry-max-entries) |
269 |
alist ; just return the alist |
alist ; just return the alist |
270 |
;; else, when given max-entries, trim the alist |
;; else, when given max-entries, trim the alist |
271 |
(let ((timehash (make-hash-table |
(let* ((timehash (make-hash-table |
272 |
:size 4096 |
:size 4096 |
273 |
:test 'equal))) |
:test 'equal)) |
274 |
|
(trim-length (- (length alist) gnus-registry-max-entries)) |
275 |
|
(trim-length (if (natnump trim-length) trim-length 0))) |
276 |
(maphash |
(maphash |
277 |
(lambda (key value) |
(lambda (key value) |
278 |
(puthash key (gnus-registry-fetch-extra key 'mtime) timehash)) |
(puthash key (gnus-registry-fetch-extra key 'mtime) timehash)) |
279 |
gnus-registry-hashtb) |
gnus-registry-hashtb) |
280 |
|
|
281 |
;; we use the return value of this setq, which is the trimmed alist |
;; we use the return value of this setq, which is the trimmed alist |
282 |
(setq alist |
(setq alist |
283 |
(nthcdr |
(nthcdr |
284 |
(- (length alist) gnus-registry-max-entries) |
trim-length |
285 |
(sort alist |
(sort alist |
286 |
(lambda (a b) |
(lambda (a b) |
287 |
(time-less-p |
(time-less-p |
288 |
(cdr (gethash (car a) timehash)) |
(cdr (gethash (car a) timehash)) |
289 |
(cdr (gethash (car b) timehash)))))))))) |
(cdr (gethash (car b) timehash)))))))))) |
290 |
|
|
291 |
(defun alist-to-hashtable (alist) |
(defun alist-to-hashtable (alist) |
292 |
"Build a hashtable from the values in ALIST." |
"Build a hashtable from the values in ALIST." |