aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMattias EngdegÄrd2022-07-19 11:59:37 +0200
committerMattias EngdegÄrd2022-07-19 12:09:33 +0200
commitc80adde1d95b1da45039e6ec39fa7dd12aab2a33 (patch)
tree5c36904aa42d3ef5a9c3d0da1a7b70c34f787161 /test
parent4b807380cf756796ce197ac58cbbbe381c157a91 (diff)
downloademacs-c80adde1d95b1da45039e6ec39fa7dd12aab2a33.tar.gz
emacs-c80adde1d95b1da45039e6ec39fa7dd12aab2a33.zip
Speed up `butlast`
* lisp/subr.el (butlast): Don't duplicate the removed part. * test/lisp/subr-tests.el (subr-tests--butlast-ref, subr-butlast): Add test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/subr-tests.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index ced2bc5c4e5..f5c1c40263e 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1090,5 +1090,22 @@ final or penultimate step during initialization."))
1090 (should-not (plistp '(1 2 3))) 1090 (should-not (plistp '(1 2 3)))
1091 (should-not (plistp '(1 2 3 . 4)))) 1091 (should-not (plistp '(1 2 3 . 4))))
1092 1092
1093(defun subr-tests--butlast-ref (list &optional n)
1094 "Reference implementation of `butlast'."
1095 (let ((m (or n 1))
1096 (len (length list)))
1097 (let ((r nil))
1098 (while (and list (> len m))
1099 (push (car list) r)
1100 (setq list (cdr list))
1101 (setq len (1- len)))
1102 (nreverse r))))
1103
1104(ert-deftest subr-butlast ()
1105 (dolist (l '(nil '(a) '(a b) '(a b c) '(a b c d)))
1106 (dolist (n (cons nil (number-sequence -2 6)))
1107 (should (equal (butlast l n)
1108 (subr-tests--butlast-ref l n))))))
1109
1093(provide 'subr-tests) 1110(provide 'subr-tests)
1094;;; subr-tests.el ends here 1111;;; subr-tests.el ends here