emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp a37cc95 4/6: * Memoize `comp-common-supertype'


From: Andrea Corallo
Subject: feature/native-comp a37cc95 4/6: * Memoize `comp-common-supertype'
Date: Thu, 12 Nov 2020 18:11:56 -0500 (EST)

branch: feature/native-comp
commit a37cc95e21675e4f8865a9c20c8acfc158a9827a
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    * 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 5965491..583a336 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."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]