[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree ba2eba0 107/154: Exploit lexical closures to
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree ba2eba0 107/154: Exploit lexical closures to allow byte-compilation of wrapped functions. |
Date: |
Mon, 14 Dec 2020 12:21:55 -0500 (EST) |
branch: externals/dict-tree
commit ba2eba0c1949b2b7bdadcc6efc3339fd594cfb11
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.
---
dict-tree.el | 101 +++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 67 insertions(+), 34 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 64a44fc..4403d58 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -143,7 +143,7 @@ If START or END is negative, it counts from the end."
;; ----------------------------------------------------------------
;; Dictionary cache entry structures
-;; Note: We *could* us a defstruct for the cache entries, but for
+;; Note: We *could* use a defstruct for the cache entries, but for
;; something this simple it doesn't seem worth it, especially
;; given that we're using the defalias approach anyway for the
;; data cells (above).
@@ -167,34 +167,67 @@ If START or END is negative, it counts from the end."
;; ----------------------------------------------------------------
;; Wrapping functions
-(defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
- ;; return wrapped insfun to deal with data wrapping
- `(lambda (new old)
- (dictree--cell-set-data old (,insfun (dictree--cell-data new)
- (dictree--cell-data old)))
- old))
+;; return wrapped insfun to deal with data wrapping
+(if (trie-lexical-binding-p)
+ (defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
+ (lambda (new old)
+ (dictree--cell-set-data old (funcall insfun
+ (dictree--cell-data new)
+ (dictree--cell-data old)))
+ old))
+ (defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
+ `(lambda (new old)
+ (dictree--cell-set-data old (,insfun (dictree--cell-data new)
+ (dictree--cell-data old)))
+ old)))
+
+
+;; return wrapped rankfun to deal with data wrapping
+(if (trie-lexical-binding-p)
+ (defun dictree--wrap-rankfun (rankfun) ; INTERNAL USE ONLY
+ (lambda (a b)
+ (funcall rankfun
+ (cons (car a) (dictree--cell-data (cdr a)))
+ (cons (car b) (dictree--cell-data (cdr b))))))
+ (defun dictree--wrap-rankfun (rankfun) ; INTERNAL USE ONLY
+ `(lambda (a b)
+ (,rankfun (cons (car a) (dictree--cell-data (cdr a)))
+ (cons (car b) (dictree--cell-data (cdr b)))))))
+
+
+;; return wrapped combfun to deal with data wrapping
+(if (trie-lexical-binding-p)
+ (defun dictree--wrap-combfun (combfun) ; INTERNAL USE ONLY
+ (lambda (cell1 cell2)
+ (cons (funcall combfun
+ (dictree--cell-data cell1)
+ (dictree--cell-data cell2))
+ (append (dictree--cell-plist cell1)
+ (dictree--cell-plist cell2)))))
+ (defun dictree--wrap-combfun (combfun) ; INTERNAL USE ONLY
+ `(lambda (cell1 cell2)
+ (cons (,combfun (dictree--cell-data cell1)
+ (dictree--cell-data cell2))
+ (append (dictree--cell-plist cell1)
+ (dictree--cell-plist cell2))))))
+
+
+;; return wrapped filter function to deal with data wrapping
+(if (trie-lexical-binding-p)
+ (defun dictree--wrap-filter (filter) ; INTERNAL USE ONLY
+ (lambda (key data) (funcall filter key (dictree--cell-data data))))
+ (defun dictree--wrap-filter (filter) ; INTERNAL USE ONLY
+ `(lambda (key data) (,filter key (dictree--cell-data data)))))
+
+
+;; return wrapped result function to deal with data wrapping
+(if (trie-lexical-binding-p)
+ (defun dictree--wrap-resultfun (resultfun) ; INTERNAL USE ONLY
+ (lambda (res)
+ (funcall resultfun (car res) (dictree--cell-data (cdr res)))))
+ (defun dictree--wrap-resultfun (resultfun) ; INTERNAL USE ONLY
+ `(lambda (res) (,resultfun (car res) (dictree--cell-data (cdr res))))))
-(defun dictree--wrap-rankfun (rankfun) ; INTERNAL USE ONLY
- ;; return wrapped rankfun to deal with data wrapping
- `(lambda (a b)
- (,rankfun (cons (car a) (dictree--cell-data (cdr a)))
- (cons (car b) (dictree--cell-data (cdr b))))))
-
-(defun dictree--wrap-combfun (combfun) ; INTERNAL USE ONLY
- ;; return wrapped combfun to deal with data wrapping
- `(lambda (cell1 cell2)
- (cons (,combfun (dictree--cell-data cell1)
- (dictree--cell-data cell2))
- (append (dictree--cell-plist cell1)
- (dictree--cell-plist cell2)))))
-
-(defun dictree--wrap-filter (filter) ; INTERNAL USE ONLY
- ;; return wrapped filter function to deal with data wrapping
- `(lambda (key data) (,filter key (dictree--cell-data data))))
-
-(defun dictree--wrap-resultfun (resultfun) ; INTERNAL USE ONLY
- ;; return wrapped result function to deal with data wrapping
- `(lambda (res) (,resultfun (car res) (dictree--cell-data (cdr res)))))
@@ -212,7 +245,7 @@ If START or END is negative, it counts from the end."
(file-name-sans-extension
(file-name-nondirectory filename))))
autosave
- unlisted
+ _unlisted
(comparison-function '<)
(insert-function (lambda (a _b) a))
(rank-function (lambda (a b) (> (cdr a) (cdr b))))
@@ -226,10 +259,10 @@ If START or END is negative, it counts from the end."
key-savefun key-loadfun
data-savefun data-loadfun
plist-savefun plist-loadfun
- trie-type
+ (trie-type 'avl)
&aux
(modified nil)
- (trie (trie-create comparison-function))
+ (trie (make-trie comparison-function trie-type))
(insfun (dictree--wrap-insfun insert-function))
(rankfun (dictree--wrap-rankfun rank-function))
(lookup-cache
@@ -261,7 +294,7 @@ If START or END is negative, it counts from the end."
(file-name-sans-extension
(file-name-nondirectory filename))))
autosave
- unlisted
+ _unlisted
(comparison-function '<)
(insert-function (lambda (a _b) a))
(rank-function (lambda (a b) (> (cdr a) (cdr b))))
@@ -282,7 +315,7 @@ If START or END is negative, it counts from the end."
transform-for-print transform-from-read
&aux
(modified nil)
- (trie (trie-create-custom
+ (trie (make-trie-custom
comparison-function
:createfun createfun
:insertfun insertfun
@@ -345,7 +378,7 @@ If START or END is negative, it counts from the end."
(name (file-name-sans-extension
(file-name-nondirectory filename)))
autosave
- unlisted
+ _unlisted
(combine-function '+)
(cache-policy 'time)
(cache-update-policy 'synchronize)
- [elpa] externals/dict-tree 5cc5449 091/154: Fixed obsolete functions and other compiler warnings., (continued)
- [elpa] externals/dict-tree 5cc5449 091/154: Fixed obsolete functions and other compiler warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 0ea66e7 090/154: Added fboundp guard around ad-define-subr-args (removed in Emacs-24)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree cfdc73d 099/154: Fixed calls to dictree-create-meta-dict., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2a1d749 098/154: Minor change to package description, to match other data structure packages., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7ab8f94 095/154: Updated copyright attribution and license (GPL2 -> GPL3)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 09b388f 108/154: Add note to self to use cust-print pretty-printing instead of advice., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d96b1c5 097/154: More minor whitespace and commentary changes., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1ec9d58 102/154: Restore trie print/read transformer functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 48ab389 092/154: Simplified persistent-storage code for tries and dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 454c68b 109/154: Code cleanup., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree ba2eba0 107/154: Exploit lexical closures to allow byte-compilation of wrapped functions.,
Stefan Monnier <=
- [elpa] externals/dict-tree 08303f3 103/154: Remove ChangeLogs from library headers., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8d8ce4f 120/154: Print dict-tree cache sizes in edebug., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 84b23ec 112/154: Implement trie-fuzzy-match and trie-fuzzy-complete functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5321c25 113/154: Implement fuzzy match and completion on dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d0e339d 117/154: Don't wrap rank and filter functions for regexp and fuzzy queries., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a11f2a5 115/154: Update predictive mode to new dictree-create function interface., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 217c9d2 119/154: Updated Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 95d6a5a 127/154: Mention iterator generators in Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d84725e 124/154: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f47d49c 137/154: Bug fixes to meta-dict fuzzy-matching/completing., Stefan Monnier, 2020/12/14