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

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

[elpa] externals/pyim 35abda6 1/2: pyim-dcache-set-variable -> pyim-dcac


From: ELPA Syncer
Subject: [elpa] externals/pyim 35abda6 1/2: pyim-dcache-set-variable -> pyim-dcache-init-variable and pyim-dcache-update-variable
Date: Tue, 14 Dec 2021 10:57:30 -0500 (EST)

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

    pyim-dcache-set-variable -> pyim-dcache-init-variable and 
pyim-dcache-update-variable
    
        * pyim-dhashcache.el (pyim-dhashcache-update-ishortcode2word)
        (pyim-dhashcache-update-shortcode2word)
        (pyim-dhashcache-update-code2word)
        (pyim-dhashcache-update-icode2word):
    
        * pyim-dcache.el (pyim-dcache-init-variable):
---
 pyim-dcache.el     | 31 +++++++++++++++++--------------
 pyim-dhashcache.el | 38 +++++++++++++++++++-------------------
 pyim-dregcache.el  |  5 ++---
 3 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index d88d00f..0a43521 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -84,25 +84,28 @@ dcache 文件的方法让 pyim 正常工作。")
   "初始化 dcache 缓存相关变量."
   (pyim-dcache-call-api 'init-variables))
 
-(defun pyim-dcache-get-variable (variable)
+(defun pyim-dcache-init-variable (variable &optional fallback-value)
+  "初始化 VARIABLE.
+
+如果 VARIABLE 的值为 nil, 则使用 ‘pyim-dcache-directory’ 中对应文
+件的内容来设置 VARIABLE 变量, 如果此时 VARIABLE 取值还是 nil, 那
+么就将 VARIABLE 的值设置为 FALLBACK-VALUE."
+  (unless (symbol-value variable)
+    (set variable (or (pyim-dcache-get-value variable)
+                      fallback-value
+                      (make-hash-table :test #'equal)))))
+
+(defun pyim-dcache-update-variable (variable)
+  "更新 VARIABLE"
+  (set variable (or (pyim-dcache-get-value variable)
+                    (make-hash-table :test #'equal))))
+
+(defun pyim-dcache-get-value (variable)
   "从 `pyim-dcache-directory' 中读取与 VARIABLE 对应的文件中保存的值."
   (let ((file (expand-file-name (symbol-name variable)
                                 pyim-dcache-directory)))
     (pyim-dcache-get-value-from-file file)))
 
-(defun pyim-dcache-set-variable (variable &optional force-restore 
fallback-value)
-  "设置变量.
-
-如果 VARIABLE 的值为 nil, 则使用 ‘pyim-dcache-directory’ 中对应文件的内容来设置
-VARIABLE 变量,FORCE-RESTORE 设置为 t 时,强制恢复,变量原来的值将丢失。
-如果获取的变量值为 nil 时,将 VARIABLE 的值设置为 FALLBACK-VALUE ."
-  (when (or force-restore (not (symbol-value variable)))
-    (let ((file (expand-file-name (symbol-name variable)
-                                  pyim-dcache-directory)))
-      (set variable (or (pyim-dcache-get-value-from-file file)
-                        fallback-value
-                        (make-hash-table :test #'equal))))))
-
 (defun pyim-dcache-save-variable (variable value)
   "将 VARIABLE 变量的取值保存到 `pyim-dcache-directory' 中对应文件中."
   (let ((file (expand-file-name (symbol-name variable)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index eb9e430..c564906 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -117,15 +117,15 @@
      `(lambda ()
         ,@(pyim-dhashcache-async-inject-variables)
         (require 'pyim-dhashcache)
-        (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
-        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (pyim-dcache-init-variable 'pyim-dhashcache-icode2word)
+        (pyim-dcache-init-variable 'pyim-dhashcache-iword2count)
         (pyim-dcache-save-variable
          'pyim-dhashcache-ishortcode2word
          (pyim-dhashcache-update-ishortcode2word-1
           pyim-dhashcache-icode2word
           pyim-dhashcache-iword2count)))
      (lambda (_)
-       (pyim-dcache-set-variable 'pyim-dhashcache-ishortcode2word t)))))
+       (pyim-dcache-update-variable 'pyim-dhashcache-ishortcode2word)))))
 
 (defun pyim-dhashcache-update-ishortcode2word-1 (icode2word iword2count)
   "`pyim-dhashcache-update-ishortcode2word' 内部函数."
@@ -159,15 +159,15 @@
      `(lambda ()
         ,@(pyim-dhashcache-async-inject-variables)
         (require 'pyim-dhashcache)
-        (pyim-dcache-set-variable 'pyim-dhashcache-code2word)
-        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (pyim-dcache-init-variable 'pyim-dhashcache-code2word)
+        (pyim-dcache-init-variable 'pyim-dhashcache-iword2count)
         (pyim-dcache-save-variable
          'pyim-dhashcache-shortcode2word
          (pyim-dhashcache-update-shortcode2word-1
           pyim-dhashcache-code2word
           pyim-dhashcache-iword2count)))
      (lambda (_)
-       (pyim-dcache-set-variable 'pyim-dhashcache-shortcode2word t)))))
+       (pyim-dcache-update-variable 'pyim-dhashcache-shortcode2word)))))
 
 (defun pyim-dhashcache-update-shortcode2word-1 (code2word iword2count)
   "`pyim-dhashcache-update-shortcode2word' 的内部函数"
@@ -274,8 +274,8 @@ DCACHE 是一个 code -> words 的 hashtable.
             (pyim-dhashcache-generate-word2code-dcache-file dcache 
,word2code-file))
           (pyim-dcache-save-value-to-file ',dicts-md5 ,code2word-md5-file))
        (lambda (_)
-         (pyim-dcache-set-variable 'pyim-dhashcache-code2word t)
-         (pyim-dcache-set-variable 'pyim-dhashcache-word2code t)
+         (pyim-dcache-init-variable 'pyim-dhashcache-code2word t)
+         (pyim-dcache-init-variable 'pyim-dhashcache-word2code t)
          (pyim-dhashcache-update-shortcode2word force)
          (setq pyim-dhashcache-update-code2word-running-p nil))))))
 
@@ -339,8 +339,8 @@ code 对应的中文词条了。
      `(lambda ()
         ,@(pyim-dhashcache-async-inject-variables)
         (require 'pyim-dhashcache)
-        (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
-        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (pyim-dcache-init-variable 'pyim-dhashcache-icode2word)
+        (pyim-dcache-init-variable 'pyim-dhashcache-iword2count)
         (maphash
          (lambda (key value)
            (puthash key (pyim-dhashcache-sort-words value 
pyim-dhashcache-iword2count)
@@ -351,7 +351,7 @@ code 对应的中文词条了。
          pyim-dhashcache-icode2word)
         nil)
      (lambda (_)
-       (pyim-dcache-set-variable 'pyim-dhashcache-icode2word t)
+       (pyim-dcache-update-variable 'pyim-dhashcache-icode2word)
        (pyim-dhashcache-update-ishortcode2word force)))))
 
 (defun pyim-dhashcache-upgrade-icode2word ()
@@ -389,12 +389,12 @@ code 对应的中文词条了。
 
 (defun pyim-dhashcache-init-variables ()
   "初始化 dcache 缓存相关变量."
-  (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
-  (pyim-dcache-set-variable 'pyim-dhashcache-code2word)
-  (pyim-dcache-set-variable 'pyim-dhashcache-word2code)
-  (pyim-dcache-set-variable 'pyim-dhashcache-shortcode2word)
-  (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
-  (pyim-dcache-set-variable 'pyim-dhashcache-ishortcode2word))
+  (pyim-dcache-init-variable 'pyim-dhashcache-iword2count)
+  (pyim-dcache-init-variable 'pyim-dhashcache-code2word)
+  (pyim-dcache-init-variable 'pyim-dhashcache-word2code)
+  (pyim-dcache-init-variable 'pyim-dhashcache-shortcode2word)
+  (pyim-dcache-init-variable 'pyim-dhashcache-icode2word)
+  (pyim-dcache-init-variable 'pyim-dhashcache-ishortcode2word))
 
 (defun pyim-dhashcache-save-personal-dcache-to-file ()
   ;; 用户选择过的词
@@ -428,10 +428,10 @@ code 对应的中文词条了。
     pyim-dhashcache-iword2count word
     (cond
      ((functionp wordcount-handler)
-      (funcall wordcount-handler orig-value))
+      (funcall wordcount-handler (or orig-value 0)))
      ((numberp wordcount-handler)
       wordcount-handler)
-     (t orig-value))))
+     (t (or orig-value 0)))))
 
 (defun pyim-dhashcache-delete-word (word)
   "将中文词条 WORD 从个人词库中删除"
diff --git a/pyim-dregcache.el b/pyim-dregcache.el
index 23b0367..96c1f08 100644
--- a/pyim-dregcache.el
+++ b/pyim-dregcache.el
@@ -328,13 +328,12 @@ DICT-FILES 是词库文件列表. DICTS-MD5 是词库的MD5校验码.
 
 (defun pyim-dregcache-init-variables ()
   "初始化 cache 缓存相关变量."
-  (pyim-dcache-set-variable
+  (pyim-dcache-init-variable
    'pyim-dregcache-iword2count
-   nil
    ;; dregcache 引擎也需要词频信息,第一次使用 dregcache 引擎的时候,
    ;; 自动导入 dhashcache 引擎的词频信息,以后两个引擎的词频信息就
    ;; 完全分开了。
-   (pyim-dcache-get-variable 'pyim-dhashcache-iword2count))
+   (pyim-dcache-get-value 'pyim-dhashcache-iword2count))
   (unless pyim-dregcache-icode2word
     (pyim-dregcache-update-personal-words t)))
 



reply via email to

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