]> git.eshelyaron.com Git - emacs.git/commit
* lisp/emacs-lisp/cl-macs.el: Optimize self-calls in tail position
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 9 Jan 2021 00:59:16 +0000 (19:59 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sat, 9 Jan 2021 00:59:31 +0000 (19:59 -0500)
commit29c7f8c915c3889dfd5b25878aa0692f826cd38f
tree50eebd6fdd68eff7398f4d20c040c17752cd9933
parent6e73e07a6f5cbdd1c5ae6e0f3fbd0f8f56813f1a
* lisp/emacs-lisp/cl-macs.el: Optimize self-calls in tail position

Implement a limited form of tail-call optimization for the special
case of recursive functions defined with `cl-labels`.  Only self-recursion
is optimized, no attempt is made to handle more complex cases such a mutual
recursion.

The main benefit is to reduce the use of the stack, tho in my limited
tests, this can also improve performance (about half of the way to
a hand-written `while` loop).

(cl--self-tco): New function.
(cl-labels): Use it.

* lisp/subr.el (letrec): Optimize single-binding corner case.

* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs--labels): Add tests
to check that TCO is working.
lisp/emacs-lisp/cl-macs.el
lisp/subr.el
test/lisp/emacs-lisp/cl-macs-tests.el