From a37cc95e21675e4f8865a9c20c8acfc158a9827a Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Thu, 12 Nov 2020 21:59:59 +0100 Subject: [PATCH] * Memoize `comp-common-supertype' * lisp/emacs-lisp/comp.el (comp-ctxt): Add `common-supertype-mem' slot. (comp-common-supertype): Memoize. --- lisp/emacs-lisp/comp.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 59654913977..583a3364dfa 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -308,7 +308,10 @@ This is tipically for top-level forms other than defun.") :documentation "When non-nil support late load.") (union-typesets-mem (make-hash-table :test #'equal) :type hash-table :documentation "Serve memoization for -`comp-union-typesets'.")) +`comp-union-typesets'.") + (common-supertype-mem (make-hash-table :test #'equal) :type hash-table + :documentation "Serve memoization for +`comp-common-supertype'.")) (cl-defstruct comp-args-base (min nil :type number @@ -2252,7 +2255,10 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non-nil." (defun comp-common-supertype (&rest types) "Return the first common supertype of TYPES." - (cl-reduce #'comp-common-supertype-2 types)) + (or (gethash types (comp-ctxt-common-supertype-mem comp-ctxt)) + (puthash types + (cl-reduce #'comp-common-supertype-2 types) + (comp-ctxt-common-supertype-mem comp-ctxt)))) (defsubst comp-subtype-p (type1 type2) "Return t if TYPE1 is a subtype of TYPE1 or nil otherwise." -- 2.39.5