* lisp/emacs-lisp/map.el (map-into) <hash-table>: Allow keyword args

(map--into-hash): New function, extracted from `map-into <hash-table>`.
Speed it up a bit by using gethash instead of map-elt when we know
we're accessing a hash table.

* test/lisp/emacs-lisp/map-tests.el (test-map-into): Add corresponding test.
This commit is contained in:
Andrea Corallo 2019-10-11 12:18:21 -04:00 committed by Stefan Monnier
parent 65cda95be4
commit 421db07d06
3 changed files with 28 additions and 10 deletions

View file

@ -340,7 +340,8 @@ Evaluate BODY for each created map.
(ert-deftest test-map-into ()
(let* ((alist '((a . 1) (b . 2)))
(ht (map-into alist 'hash-table)))
(ht (map-into alist 'hash-table))
(ht2 (map-into alist '(hash-table :test equal))))
(should (hash-table-p ht))
(should (equal (map-into (map-into alist 'hash-table) 'list)
alist))
@ -349,6 +350,8 @@ Evaluate BODY for each created map.
(map-keys ht)))
(should (equal (map-values (map-into (map-into ht 'list) 'hash-table))
(map-values ht)))
(should (equal (map-into ht 'alist) (map-into ht2 'alist)))
(should (eq (hash-table-test ht2) 'equal))
(should (null (map-into nil 'list)))
(should (map-empty-p (map-into nil 'hash-table)))
(should-error (map-into [1 2 3] 'string))))