emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/pyim e63b221a6c 1/4: * pyim-dcache.el (pyim-dcache-back


From: ELPA Syncer
Subject: [elpa] externals/pyim e63b221a6c 1/4: * pyim-dcache.el (pyim-dcache-backend): New function.
Date: Thu, 9 Jun 2022 18:57:49 -0400 (EDT)

branch: externals/pyim
commit e63b221a6cb372c8014adfc036114f9415215355
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    * pyim-dcache.el (pyim-dcache-backend): New function.
---
 pyim-dcache.el      | 24 +++++++++++++++++++-----
 tests/pyim-tests.el | 12 ++++++++++++
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index b1789800cc..0d3a011f5b 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -30,6 +30,7 @@
 (require 'cl-lib)
 (require 'pyim-common)
 (require 'pyim-pymap)
+(require 'pyim-scheme)
 (require 'url-util)
 
 (defgroup pyim-dcache nil
@@ -49,7 +50,8 @@
 `pyim-dregcache' 速度和词库大小成正比.  当词库接近100M大小时,
 在六年历史的笔记本上会有一秒的延迟. 这时建议换用 `pyim-dhashcache'.
 
-注意:`pyim-dregcache' 只支持全拼和双拼输入法,不支持其它型码输入法."
+注意:`pyim-dregcache' 只支持全拼和双拼输入法,不支持其它型码输入
+法。"
   :type 'symbol)
 
 (defvar pyim-dcache-auto-update t
@@ -172,14 +174,27 @@ AUTO-BACKUP-THRESHOLD 倍, 那么原值将自动备份到 FILE 对应的备份
      (setq ,variable (or (pyim-dcache-get-value ',variable)
                          (make-hash-table :test #'equal)))))
 
+;; ** Dcache 后端加载相关函数
+(defun pyim-dcache-load-backend ()
+  "检查 `pyim-dcache-backend' 设置并 require 相应 package."
+  (let ((backend (pyim-dcache-backend)))
+    (unless (featurep backend)
+      (require backend))))
+
+(defun pyim-dcache-backend ()
+  "返回当前可用的 dcache backend."
+  (if (and (eq pyim-dcache-backend 'pyim-dregcache)
+           (pyim-scheme-quanpin-p (pyim-scheme-current)))
+      'pyim-dregcache
+    'pyim-dhashcache))
+
 ;; ** Dcache 初始化功能接口
 (cl-defgeneric pyim-dcache-init-variables ()
   "初始化 dcache 缓存相关变量."
   nil)
 
 (cl-defmethod pyim-dcache-init-variables :before ()
-  (unless (featurep pyim-dcache-backend)
-    (require pyim-dcache-backend)))
+  (pyim-dcache-load-backend))
 
 ;; ** Dcache 检索词条功能接口
 (cl-defgeneric pyim-dcache-get (_code &optional _from)
@@ -190,8 +205,7 @@ code 对应的中文词条了."
   nil)
 
 (cl-defmethod pyim-dcache-get :before (_code &optional _from)
-  (unless (featurep pyim-dcache-backend)
-    (require pyim-dcache-backend)))
+  (pyim-dcache-load-backend))
 
 ;; ** Dcache 代码反查功能接口
 (cl-defgeneric pyim-dcache-search-word-code (word)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 03b7b97b3e..3a6edc5400 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -948,6 +948,18 @@
       (should (equal (gethash "测伌" pyim-dhashcache-iword2count) 0)))))
 
 ;; ** pyim-dcache 相关单元测试
+(ert-deftest pyim-tests-pyim-dcache-backend ()
+  (let ((pyim-dcache-backend 'pyim-dregcache)
+        (pyim-default-scheme 'quanpin))
+    (should (eq (pyim-dcache-backend) 'pyim-dregcache)))
+
+  (let ((pyim-dcache-backend 'pyim-dregcache)
+        (pyim-default-scheme 'wubi))
+    (should (eq (pyim-dcache-backend) 'pyim-dhashcache)))
+
+  (let ((pyim-dcache-backend 'pyim-dhashcache1))
+    (should (eq (pyim-dcache-backend) 'pyim-dhashcache))))
+
 (ert-deftest pyim-tests-pyim-dcache-save/read-variable-value ()
   (let* ((file (pyim-tests-make-temp-file))
          (backup-file (concat file "-backup-" (format-time-string 
"%Y%m%d%H%M%S")))



reply via email to

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