]> git.eshelyaron.com Git - emacs.git/commit
(derived-mode-all-parents): Speed up with a cache
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 8 Nov 2023 19:20:09 +0000 (14:20 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 9 Nov 2023 03:42:16 +0000 (22:42 -0500)
commit9c6b22bb3e2126a1ab355b81ae4268ac53c2b6fe
treebac6574c1b211ead218bb7003e5339f66adc89ce
parent19445b6b7bb04e44e39ef2e39a620bd3eadb0acd
(derived-mode-all-parents): Speed up with a cache

Most uses of the mode hierarchy don't really need to construct the
list, they just need to iterate over it.  With single inheritance
we could do it just by jumping up from a mode to its parent,
but to support the upcoming multiple inheritance we'd need a more
complex and costly iterator.
Luckily, the inheritance graph is mostly static so we can cache
the list of all parents, making `derived-mode-all-parents` cheap
enough to be the basis of iteration and keeping the API very simple.

* lisp/subr.el (derived-mode-all-parents): Cache the result.
(derived-mode--flush): New function.
(derived-mode-set-parent): Use it.
lisp/subr.el