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

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

[elpa] externals/pyim d754b7ac29 3/4: Revert "cl-defgeneric pyim-dcache-


From: ELPA Syncer
Subject: [elpa] externals/pyim d754b7ac29 3/4: Revert "cl-defgeneric pyim-dcache-get."
Date: Wed, 8 Jun 2022 22:57:55 -0400 (EDT)

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

    Revert "cl-defgeneric pyim-dcache-get."
    
    This reverts commit 5989a6c43c323db680254c6900091361c6e9ddd9.
---
 pyim-dcache.el      |  6 ++++--
 pyim-dhashcache.el  | 39 ++++++++++++++++++---------------------
 pyim-dregcache.el   | 45 +++++++++++++++++++++------------------------
 tests/pyim-tests.el | 13 ++++++-------
 4 files changed, 49 insertions(+), 54 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index 22cf9fcf02..4011eef215 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -265,11 +265,13 @@ non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式"
   "将中文词条 WORD 从个人词库中删除")
 
 ;; ** Dcache 检索功能
-(cl-defgeneric pyim-dcache-get (code &optional from)
+(defun pyim-dcache-get (code &optional from)
   "从 FROM 对应的 dcache 中搜索 CODE, 得到对应的词条.
 
 当词库文件加载完成后,pyim 就可以用这个函数从词库缓存中搜索某个
-code 对应的中文词条了.")
+code 对应的中文词条了."
+  (when code
+    (pyim-dcache-call-api 'get code from)))
 
 ;; * Footer
 (provide 'pyim-dcache)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index ddaa04f26b..40cd36423f 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -396,9 +396,7 @@ DCACHE 是一个 code -> words 的 hashtable.
      dcache)
     (pyim-dcache-write-file file confirm)))
 
-(cl-defmethod pyim-dcache-get
-  (code &context (pyim-dcache-backend (eql pyim-dhashcache))
-        &optional from)
+(defun pyim-dhashcache-get (code &optional from)
   "从 FROM 对应的 dcaches 中搜索 CODE, 得到对应的词条.
 
 当词库文件加载完成后,pyim 就可以用这个函数从词库缓存中搜索某个
@@ -406,24 +404,23 @@ code 对应的中文词条了。
 
 如果 FROM 为 nil, 则默认搜索 `pyim-dhashcache-icode2word' 和
 `pyim-dhashcache-code2word' 两个 dcache."
-  (when code
-    (let* ((caches (mapcar (lambda (x)
-                             (intern (concat "pyim-dhashcache-" (symbol-name 
x))))
-                           (or (and from
-                                    (if (listp from)
-                                        from
-                                      (list from)))
-                               '(icode2word code2word))))
-           result)
-      (dolist (cache caches)
-        (let* ((cache (ignore-errors (symbol-value cache)))
-               (value (and cache (gethash code cache))))
-          ;; 处理 iword2count.
-          (unless (listp value)
-            (setq value (list value)))
-          (when value
-            (setq result (append result value)))))
-      result)))
+  (let* ((caches (mapcar (lambda (x)
+                           (intern (concat "pyim-dhashcache-" (symbol-name 
x))))
+                         (or (and from
+                                  (if (listp from)
+                                      from
+                                    (list from)))
+                             '(icode2word code2word))))
+         result)
+    (dolist (cache caches)
+      (let* ((cache (ignore-errors (symbol-value cache)))
+             (value (and cache (gethash code cache))))
+        ;; 处理 iword2count.
+        (unless (listp value)
+          (setq value (list value)))
+        (when value
+          (setq result (append result value)))))
+    result))
 
 (defun pyim-dhashcache-update-icode2word (&optional force)
   "对 personal 缓存中的词条进行排序,加载排序后的结果.
diff --git a/pyim-dregcache.el b/pyim-dregcache.el
index 9133e9b015..638d5adb28 100644
--- a/pyim-dregcache.el
+++ b/pyim-dregcache.el
@@ -261,31 +261,28 @@ DICT-FILES 是词库文件列表. DICTS-MD5 是词库的MD5校验码.
       (setq start (+ start 2 (length code) (length word))))
     output))
 
-(cl-defmethod pyim-dcache-get
-  (code &context (pyim-dcache-backend (eql pyim-dregcache))
-        &optional from)
+(defun pyim-dregcache-get (code &optional from)
   "从 `pyim-dregcache-cache' 搜索 CODE, 得到对应的词条."
-  (when code
-    (cond ((or (memq 'icode2word from)
-               (memq 'ishortcode2word from))
-           (pyim-dregcache-get-icode2word-ishortcode2word code))
-          ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和
-          ;; iword2count-recent-50-words.
-          ((or (memq 'iword2count-recent-10-words from)
-               (memq 'iword2count-recent-50-words from))
-           nil)
-          (t (let ((dict-files (pyim-dregcache-all-dict-files))
-                   result)
-
-               (when pyim-debug (message "pyim-dregcache-get is called. 
code=%s" code))
-               (when dict-files
-                 (dolist (file dict-files)
-                   (let* ((file-info (lax-plist-get pyim-dregcache-cache file))
-                          (content (pyim-dregcache-get-content code 
file-info)))
-                     (setq result (append (pyim-dregcache-get-1 content code) 
result)))))
-               ;; `push' plus `nreverse' is more efficient than `add-to-list'
-               ;; Many examples exist in Emacs' own code
-               (nreverse result))))))
+  (cond ((or (memq 'icode2word from)
+             (memq 'ishortcode2word from))
+         (pyim-dregcache-get-icode2word-ishortcode2word code))
+        ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和
+        ;; iword2count-recent-50-words.
+        ((or (memq 'iword2count-recent-10-words from)
+             (memq 'iword2count-recent-50-words from))
+         nil)
+        (t (let ((dict-files (pyim-dregcache-all-dict-files))
+                 result)
+
+             (when pyim-debug (message "pyim-dregcache-get is called. code=%s" 
code))
+             (when dict-files
+               (dolist (file dict-files)
+                 (let* ((file-info (lax-plist-get pyim-dregcache-cache file))
+                        (content (pyim-dregcache-get-content code file-info)))
+                   (setq result (append (pyim-dregcache-get-1 content code) 
result)))))
+             ;; `push' plus `nreverse' is more efficient than `add-to-list'
+             ;; Many examples exist in Emacs' own code
+             (nreverse result)))))
 
 (defun pyim-dregcache-get-icode2word-ishortcode2word (code)
   "以 CODE 搜索个人词和个人联想词.  正则表达式搜索词库,不需要为联想词开单独缓存."
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 0e339e5d07..136a864011 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -1167,8 +1167,7 @@ yin-xing 因行
 ")))))
 
 (ert-deftest pyim-tests-pyim-dhashcache-get ()
-  (let ((pyim-dcache-backend 'pyim-dhashcache)
-        (pyim-dhashcache-code2word (make-hash-table :test #'equal))
+  (let ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
         (pyim-dhashcache-icode2word (make-hash-table :test #'equal))
         (pyim-dhashcache-iword2count (make-hash-table :test #'equal)))
 
@@ -1176,11 +1175,11 @@ yin-xing 因行
     (puthash "ni-hao" '("你好") pyim-dhashcache-code2word)
     (puthash "你好" 10 pyim-dhashcache-iword2count)
 
-    (should (equal (pyim-dcache-get "ni-hao" '(code2word)) '("你好")))
-    (should (equal (pyim-dcache-get "ni-hao" '(icode2word)) '("呢耗")))
-    (should (equal (pyim-dcache-get "你好" '(iword2count)) '(10)))
-    (should (equal (pyim-dcache-get "ni-hao" '(code2word icode2word)) '("你好" 
"呢耗")))
-    (should (equal (pyim-dcache-get "ni-hao") '("呢耗" "你好")))))
+    (should (equal (pyim-dhashcache-get "ni-hao" '(code2word)) '("你好")))
+    (should (equal (pyim-dhashcache-get "ni-hao" '(icode2word)) '("呢耗")))
+    (should (equal (pyim-dhashcache-get "你好" '(iword2count)) '(10)))
+    (should (equal (pyim-dhashcache-get "ni-hao" '(code2word icode2word)) 
'("你好" "呢耗")))
+    (should (equal (pyim-dhashcache-get "ni-hao") '("呢耗" "你好")))))
 
 (ert-deftest pyim-tests-pyim-dhashcache-insert-word-into-icode2word ()
   (let ((pyim-dhashcache-icode2word (make-hash-table :test #'equal)))



reply via email to

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