mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 22:10:21 +02:00
Optimize `vhash-delete'.
* module/ice-9/vlist.scm (vhash-delete): Check whether KEY is in VHASH and return VHASH if it's not.
This commit is contained in:
parent
8bc5b79df7
commit
2a39def1a8
1 changed files with 10 additions and 8 deletions
|
@ -530,14 +530,16 @@ value of @var{result} for the first call to @var{proc}."
|
|||
(define* (vhash-delete key vhash #:optional (equal? equal?) (hash hash))
|
||||
"Remove all associations from @var{vhash} with @var{key}, comparing keys
|
||||
with @var{equal?}."
|
||||
(vlist-fold (lambda (k+v result)
|
||||
(let ((k (car k+v))
|
||||
(v (cdr k+v)))
|
||||
(if (equal? k key)
|
||||
result
|
||||
(vhash-cons k v result))))
|
||||
vlist-null
|
||||
vhash))
|
||||
(if (vhash-assoc key vhash equal? hash)
|
||||
(vlist-fold (lambda (k+v result)
|
||||
(let ((k (car k+v))
|
||||
(v (cdr k+v)))
|
||||
(if (equal? k key)
|
||||
result
|
||||
(vhash-cons k v result))))
|
||||
vlist-null
|
||||
vhash)
|
||||
vhash))
|
||||
|
||||
(define vhash-delq (cut vhash-delete <> <> eq? hashq))
|
||||
(define vhash-delv (cut vhash-delete <> <> eqv? hashv))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue