[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 4311bd0bd7: Slightly faster hash-table-keys and hash-table-values
From: |
Mattias Engdegård |
Subject: |
master 4311bd0bd7: Slightly faster hash-table-keys and hash-table-values |
Date: |
Fri, 17 Jun 2022 13:31:27 -0400 (EDT) |
branch: master
commit 4311bd0bd73c17b883d3f88eab4928a44d056a3a
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Slightly faster hash-table-keys and hash-table-values
* lisp/emacs-lisp/subr-x.el (hash-table-keys, hash-table-values):
Omit the reversal of the returned list. It is not ordered anyway.
* test/lisp/emacs-lisp/subr-x-tests.el
(subr-x--hash-table-keys-and-values): New test.
---
lisp/emacs-lisp/subr-x.el | 8 ++++++--
test/lisp/emacs-lisp/subr-x-tests.el | 7 +++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 9cd793d05c..5c3dff62c8 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -87,11 +87,15 @@ threading."
(defsubst hash-table-keys (hash-table)
"Return a list of keys in HASH-TABLE."
- (cl-loop for k being the hash-keys of hash-table collect k))
+ (let ((keys nil))
+ (maphash (lambda (k _) (push k keys)) hash-table)
+ keys))
(defsubst hash-table-values (hash-table)
"Return a list of values in HASH-TABLE."
- (cl-loop for v being the hash-values of hash-table collect v))
+ (let ((values nil))
+ (maphash (lambda (_ v) (push v values)) hash-table)
+ values))
(defsubst string-empty-p (string)
"Check whether STRING is empty."
diff --git a/test/lisp/emacs-lisp/subr-x-tests.el
b/test/lisp/emacs-lisp/subr-x-tests.el
index 7f3916c2c0..0bec9db36e 100644
--- a/test/lisp/emacs-lisp/subr-x-tests.el
+++ b/test/lisp/emacs-lisp/subr-x-tests.el
@@ -743,6 +743,13 @@
(with-current-buffer inner
(should-not (buffer-modified-p))))))))
+(ert-deftest subr-x--hash-table-keys-and-values ()
+ (let ((h (make-hash-table)))
+ (puthash 'a 1 h)
+ (puthash 'c 3 h)
+ (puthash 'b 2 h)
+ (should (equal (sort (hash-table-keys h) #'string<) '(a b c)))
+ (should (equal (sort (hash-table-values h) #'<) '(1 2 3)))))
(provide 'subr-x-tests)
;;; subr-x-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 4311bd0bd7: Slightly faster hash-table-keys and hash-table-values,
Mattias Engdegård <=