[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/trie bc12ecb 072/111: Exploit lexical closures to allow
From: |
Stefan Monnier |
Subject: |
[elpa] externals/trie bc12ecb 072/111: Exploit lexical closures to allow byte-compilation of wrapped functions. |
Date: |
Mon, 14 Dec 2020 11:35:23 -0500 (EST) |
branch: externals/trie
commit bc12ecbbefddaf2b56f7efd8beada5f33f251878
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Exploit lexical closures to allow byte-compilation of wrapped functions.
A number of functions are wrapped in a thin anonymous function before being
stored in the data structures. The wrappers were constructed as quoted
lambda
forms, so were not byte-compiled. Lexical closures allow the
wrapper-constructing functions to use unquoted lambdas, enabling
byte-compilation of the wrapped functions.
We fall back to old-style function wrapping if lexical binding unsupported.
---
trie.el | 54 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/trie.el b/trie.el
index 50fb951..3fe434c 100644
--- a/trie.el
+++ b/trie.el
@@ -225,22 +225,44 @@
transform-for-print transform-from-read print-form)
-(defun trie--wrap-cmpfun (cmpfun)
- ;; wrap CMPFUN for use in a subtree
- `(lambda (a b)
- (setq a (trie--node-split a)
- b (trie--node-split b))
- (cond ((eq a trie--terminator)
- (if (eq b trie--terminator) nil t))
- ((eq b trie--terminator) nil)
- (t (,cmpfun a b)))))
-
-
-(defun trie--construct-equality-function (comparison-function)
- ;; create equality function from trie comparison function
- `(lambda (a b)
- (and (not (,comparison-function a b))
- (not (,comparison-function b a)))))
+(defmacro trie-lexical-binding-p ()
+ "Return non-nil if lexical binding is in effect, nil otherwise."
+ (let ((tempvar (make-symbol "x")))
+ `(let ((,tempvar nil)
+ (f (let ((,tempvar t)) (lambda () ,tempvar))))
+ (funcall f))))
+
+
+;; wrap CMPFUN for use in a subtree
+(if (trie-lexical-binding-p)
+ (defun trie--wrap-cmpfun (cmpfun)
+ (lambda (a b)
+ (setq a (trie--node-split a)
+ b (trie--node-split b))
+ (cond ((eq a trie--terminator)
+ (if (eq b trie--terminator) nil t))
+ ((eq b trie--terminator) nil)
+ (t (funcall cmpfun a b)))))
+ (defun trie--wrap-cmpfun (cmpfun)
+ `(lambda (a b)
+ (setq a (trie--node-split a)
+ b (trie--node-split b))
+ (cond ((eq a trie--terminator)
+ (if (eq b trie--terminator) nil t))
+ ((eq b trie--terminator) nil)
+ (t (,cmpfun a b))))))
+
+
+;; create equality function from trie comparison function
+(if (trie-lexical-binding-p)
+ (defun trie--construct-equality-function (comparison-function)
+ (lambda (a b)
+ (and (not (funcall comparison-function a b))
+ (not (funcall comparison-function b a)))))
+ (defun trie--construct-equality-function (comparison-function)
+ `(lambda (a b)
+ (and (not (,comparison-function a b))
+ (not (,comparison-function b a))))))
- [elpa] externals/trie 58c6685 014/111: Replaced bare avl-trees, (continued)
- [elpa] externals/trie 58c6685 014/111: Replaced bare avl-trees, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 9f5b6c2 060/111: Simplified persistent-storage code for tries and dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 6aa6701 033/111: Added optional RESULTFUN argument to trie query functions,, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2345832 047/111: Advised edebug-prin1 and edebug-prin1-to-string to prevent edebug hanging, Stefan Monnier, 2020/12/14
- [elpa] externals/trie e1be744 030/111: Bug-fix in trie--do-wildcard-search, Stefan Monnier, 2020/12/14
- [elpa] externals/trie e00ae36 058/111: Trivial docstring and comment fixes., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 153d2d4 048/111: Require advice when compiling, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 6d76748 028/111: Allow "]" to be included in a negated character alternatives, by placing immediately after the "[^"., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 00300c4 074/111: Revert trie--node-data defsetf, since it seems to work now., Stefan Monnier, 2020/12/14
- [elpa] externals/trie dd26bb3 023/111: more trivial docstring changes, Stefan Monnier, 2020/12/14
- [elpa] externals/trie bc12ecb 072/111: Exploit lexical closures to allow byte-compilation of wrapped functions.,
Stefan Monnier <=
- [elpa] externals/trie e88f10d 069/111: Remove ChangeLogs from library headers., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 4efa42d 067/111: Fix trie--node-data defsetf, so it compiles in latest Emacs trunk., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 9986ac7 068/111: Restore trie print/read transformer functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie ec5396c 071/111: Suppress bogus unused lexical variable byte-compiler warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/trie acad8e8 050/111: Bug-fixes to edebug advice, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 15b4de9 018/111: Simplified trie--create by storing functions for predefined trie types in symbol property lists, Stefan Monnier, 2020/12/14
- [elpa] externals/trie fb1d096 034/111: Changed trie-wildcard-match to return grouping data if pattern matches and contains groups, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 4ff2b48 057/111: Minor typo-fixes in docstrings., Stefan Monnier, 2020/12/14
- [elpa] externals/trie a8bc50f 041/111: Minor code tidying, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 0d81a80 066/111: Remove dependency on Emacs version, since this is currently broken in ELPA., Stefan Monnier, 2020/12/14