From 33120cd64e6b961f65e8b19060b0078b4d7c9201 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 2 Mar 2017 00:42:58 -0500 Subject: [PATCH] core/autoload/memoize: another refactor (restore doom-memoize) --- core/autoload/memoize.el | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/autoload/memoize.el b/core/autoload/memoize.el index 0713d2d55..a64bb5c7a 100644 --- a/core/autoload/memoize.el +++ b/core/autoload/memoize.el @@ -6,23 +6,25 @@ "A lookup table containing memoized functions. The keys are argument lists, and the value is the function's return value.") -(defsubst doom--memoize-wrap (name) - "Return the memoized version of FUNC." +;;;###autoload +(defun doom-memoize (name) + "Memoizes an existing function. NAME is a symbol." (let ((func (symbol-function name))) - `(lambda (&rest args) - ,(documentation name) - (let ((key (cons ',name args))) - (or (gethash key doom-memoized-table) - (puthash key (apply ',func args) doom-memoized-table)))))) + (put name 'function-documentation + (concat (documentation func) " (memoized)")) + (fset name + `(lambda (&rest args) + (let ((key (cons ',name args))) + (or (gethash key doom-memoized-table) + (puthash key (apply ',func args) + doom-memoized-table))))))) ;;;###autoload (defmacro def-memoized! (name arglist &rest body) "Create a memoize'd function. NAME, ARGLIST, DOCSTRING and BODY have the same meaning as in `defun'." (declare (indent defun) (doc-string 3)) - (when (stringp (car body)) - (setcar body (concat (car body) " (memoized)"))) `(progn (defun ,name ,arglist ,@body) - (fset ',name (doom--memoize-wrap ',name)))) + (doom-memoize ',name)))