From 7c3d3b83358842857a0af99b89983cfa9a5512a1 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 19 Dec 2020 19:54:46 +0100 Subject: Convert apropos-internal from C to Lisp (Bug#44529) This runs insignificantly faster in C, and is already fast enough on reasonably modern hardware. We might as well lift it to Lisp. This benchmark can be used to verify: (benchmark-run 10 (apropos-command "test")) => (0.12032415399999999 2 0.014772391999999995) ; C => (0.13513192100000002 2 0.017216643000000004) ; Lisp * lisp/subr.el (apropos-internal): New defun, converted from C. * src/keymap.c (Fapropos_internal): Remove defun. (apropos_accum): Remove function. (apropos_predicate, apropos_accumulate): Remove variables. (syms_of_keymap): Remove defsubr for Fapropos_internal, and definitions of the above variables. * test/src/keymap-tests.el (keymap-apropos-internal) (keymap-apropos-internal/predicate): Move tests from here... * test/lisp/subr-tests.el (apropos-apropos-internal) (apropos-apropos-internal/predicate): ...to here. --- test/lisp/subr-tests.el | 12 ++++++++++++ test/src/keymap-tests.el | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index e275e4b1c89..25da19574a9 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -597,6 +597,18 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350." (undo-boundary) (undo) (should (equal (buffer-string) "")))) + +;;; Apropos. + +(ert-deftest apropos-apropos-internal () + (should (equal (apropos-internal "^next-line$") '(next-line))) + (should (>= (length (apropos-internal "^help")) 100)) + (should-not (apropos-internal "^test-a-missing-symbol-foo-bar-zot$"))) + +(ert-deftest apropos-apropos-internal/predicate () + (should (equal (apropos-internal "^next-line$" #'commandp) '(next-line))) + (should (>= (length (apropos-internal "^help" #'commandp)) 15)) + (should-not (apropos-internal "^next-line$" #'keymapp))) (provide 'subr-tests) ;;; subr-tests.el ends here diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el index 6411cd1f0d4..f58dac87401 100644 --- a/test/src/keymap-tests.el +++ b/test/src/keymap-tests.el @@ -248,19 +248,6 @@ g .. h foo 0 .. 3 foo "))))) - -;;;; apropos-internal - -(ert-deftest keymap-apropos-internal () - (should (equal (apropos-internal "^next-line$") '(next-line))) - (should (>= (length (apropos-internal "^help")) 100)) - (should-not (apropos-internal "^test-a-missing-symbol-foo-bar-zut$"))) - -(ert-deftest keymap-apropos-internal/predicate () - (should (equal (apropos-internal "^next-line$" #'commandp) '(next-line))) - (should (>= (length (apropos-internal "^help" #'commandp)) 15)) - (should-not (apropos-internal "^next-line$" #'keymapp))) - (provide 'keymap-tests) ;;; keymap-tests.el ends here -- cgit v1.2.1