[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/spell-fu 1698c51740 79/86: Store a list of hashes instead
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/spell-fu 1698c51740 79/86: Store a list of hashes instead of symbol lookups for each word |
Date: |
Thu, 7 Jul 2022 12:03:45 -0400 (EDT) |
branch: elpa/spell-fu
commit 1698c5174084fdbcd3004630172931c3deee0c27
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Store a list of hashes instead of symbol lookups for each word
This is slightly more efficient than calling symbol-value
on every dictionary.
---
spell-fu.el | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/spell-fu.el b/spell-fu.el
index b912d32fd3..f95bc4546e 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -154,6 +154,8 @@ Notes:
;; Always check this has not been deleted (has a valid buffer) before use.
(defvar-local spell-fu--idle-overlay-last nil)
+;; Cache the result of: `(mapcar (lambda (dict) (symbol-value dict))
spell-fu-dictionaries)'
+(defvar-local spell-fu--cache-table-list nil)
;; ---------------------------------------------------------------------------
;; Dictionary Utility Functions
@@ -174,6 +176,11 @@ Notes:
"Return the location of the word-list with dictionary DICT."
(expand-file-name (format "words_%s.txt" (symbol-name dict))
spell-fu-directory))
+(defun spell-fu--refresh-cache-table-list ()
+ "Refresh internal list `spell-fu--cache-table-list'."
+ (setq spell-fu--cache-table-list
+ (mapcar (lambda (dict) (symbol-value dict)) spell-fu-dictionaries)))
+
(defun spell-fu--refresh ()
"Reset spell-checked overlays in the current buffer."
;; For now simply clear syntax highlighting.
@@ -443,22 +450,31 @@ Otherwise remove all overlays."
(overlay-put item-ov 'evaporate t)
item-ov))
+(defsubst spell-fu--check-word-in-dict-list (encoded-word)
+ "Return t if ENCODED-WORD is found in `spell-fu-dictionaries'."
+ (let
+ (
+ (found nil)
+ (cache-table-list spell-fu--cache-table-list))
+ (while cache-table-list
+ (let ((cache-table (pop cache-table-list)))
+ (when (gethash encoded-word cache-table nil)
+ (setq found t)
+ (setq cache-table-list nil))))
+ found))
+
(defun spell-fu-check-word (pos-beg pos-end word)
"Run the spell checker on a word.
Marking the spelling as incorrect using `spell-fu-incorrect-face' on failure.
Argument POS-BEG the beginning position of WORD.
Argument POS-END the end position of WORD."
- (or
- ;; Dictionary search.
- (let ((encoded-word (encode-coding-string (downcase word) 'utf-8)))
- (cl-find-if
- (lambda (dict) (gethash encoded-word (symbol-value dict) nil))
- spell-fu-dictionaries))
+ ;; Dictionary search.
+ (unless (spell-fu--check-word-in-dict-list (encode-coding-string (downcase
word) 'utf-8))
;; Ignore all uppercase words.
- (equal word (upcase word))
- ;; Mark as incorrect otherwise.
- (spell-fu-mark-incorrect pos-beg pos-end)))
+ (unless (equal word (upcase word))
+ ;; Mark as incorrect otherwise.
+ (spell-fu-mark-incorrect pos-beg pos-end))))
(defun spell-fu--word-at-point ()
"Return the word at the current point or nil."
@@ -975,12 +991,14 @@ Return t when the word has been removed."
(let ((update-fun (get dict 'update)))
(when update-fun
(funcall update-fun)))
+ (spell-fu--refresh-cache-table-list)
(spell-fu--refresh)))
(defun spell-fu-dictionary-remove (dict)
"Remove DICT from the list of active dictionaries."
(setq spell-fu-dictionaries (delq dict spell-fu-dictionaries))
(when (bound-and-true-p spell-fu-mode)
+ (spell-fu--refresh-cache-table-list)
(spell-fu--refresh)))
@@ -1418,6 +1436,8 @@ Argument DICT-FILE is the absolute path to the
dictionary."
(when update-fun
(funcall update-fun))))
+ (spell-fu--refresh-cache-table-list)
+
;; We may want defaults for other modes,
;; although keep this general.
(cond
@@ -1436,6 +1456,8 @@ Argument DICT-FILE is the absolute path to the
dictionary."
(defun spell-fu-mode-disable ()
"Turn off option `spell-fu-mode' for the current buffer."
+ (kill-local-variable 'spell-fu--cache-table-list)
+
(cond
((<= spell-fu-idle-delay 0.0)
(spell-fu--immediate-disable))
- [nongnu] elpa/spell-fu 1c0424b4c9 55/86: Cleanup: minor tweak to docstring, (continued)
- [nongnu] elpa/spell-fu 1c0424b4c9 55/86: Cleanup: minor tweak to docstring, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu fd27978614 57/86: Update readme.rst, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a7879fe9e7 59/86: Cleanup: over-wide docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a2a0e3b786 60/86: Cleanup: remove redundant group properties, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 570ccd84ed 64/86: Fix spell-fu-goto-{next/prev}-error silently failing, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu b2da2874f3 67/86: Cleanup: use shorter variable names, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 00af362af3 71/86: Add multiple dictionary support, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2ba65de269 74/86: Cleanup: include all arguments in doc-strings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 4782667d7b 76/86: Fail gracefully with a message when aspell can't be found, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 3a19836c69 78/86: Cleanup: use brief SPDX license, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1698c51740 79/86: Store a list of hashes instead of symbol lookups for each word,
ELPA Syncer <=
- [nongnu] elpa/spell-fu 47d92c1989 84/86: Fix wrong function name for multiple languages example, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2590ee3002 80/86: Cleanup: remove cl-remove-if-not, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1299bfca2e 85/86: Merge pull request 'Fix wrong function name for multiple languages example' (#27) from kepi/emacs-spell-fu:master into master, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 907271a557 03/86: Cleanup: unnecessary 'let' nesting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 3898e6f591 04/86: Cleanup: remove use of exception handling, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu ae4504f14d 07/86: Fix using hard coded en_US dictionary, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu f2b7d58e87 08/86: Cleanup: correct comment, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1e6928f77d 05/86: Cleanup: add message for generating cache, some comments, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu bd76cb262e 15/86: Avoid 2x loops over the pending screen overlays, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 4f9732492c 01/86: Initial code., ELPA Syncer, 2022/07/07