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

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

[elpa] externals/pyim 5b22eb1 1/4: Dhashcache do not support thread.


From: ELPA Syncer
Subject: [elpa] externals/pyim 5b22eb1 1/4: Dhashcache do not support thread.
Date: Tue, 27 Apr 2021 08:57:10 -0400 (EDT)

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

    Dhashcache do not support thread.
    
        * pyim-dhashcache.el (pyim-dhashcache-update-ishortcode2word)
        (pyim-dhashcache-update-shortcode2word)
        (pyim-dhashcache-update-code2word)
        (pyim-dhashcache-update-icode2word): Do not support thread.
    
        * pyim-dcache.el (pyim-dcache-prefer-emacs-thread)
        (pyim-dcache-use-emacs-thread-p): removed.
        (pyim-dcache-import): Do not use pyim-dcache-prefer-emacs-thread
---
 pyim-dcache.el     |  23 +----
 pyim-dhashcache.el | 262 ++++++++++++++++++++---------------------------------
 2 files changed, 102 insertions(+), 183 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index ab00464..dc08627 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -62,23 +62,6 @@ pyim 对资源的消耗。
 2. 自动更新功能无法正常工作,用户通过手工从其他机器上拷贝
 dcache 文件的方法让 pyim 正常工作。")
 
-(define-obsolete-variable-alias 'pyim-prefer-emacs-thread 
'pyim-dcache-prefer-emacs-thread "4.0")
-(defvar pyim-dcache-prefer-emacs-thread nil
-  "是否优先使用 emacs thread 功能来生成 dcache.
-
-如果这个变量设置为 t, 那么当 emacs thread 功能可以使用时,
-pyim 优先使用 emacs thread 功能来生成 dcache, 如果设置为 nil,
-pyim 总是使用 emacs-async 包来生成 dcache.
-
-不过这个选项开启之后,会显著的减慢词库加载速度,特别是
-五笔等形码输入法。")
-
-;; ** Dcache 通用工具
-(defun pyim-dcache-use-emacs-thread-p ()
-  "判断是否使用 emacs thread 功能来生成 thread."
-  (and pyim-dcache-prefer-emacs-thread
-       (>= emacs-major-version 26)))
-
 ;; ** Dcache API 调用功能
 (defun pyim-dcache-call-api (api-name &rest api-args)
   "Get backend API named API-NAME then call it with arguments API-ARGS."
@@ -240,10 +223,8 @@ MERGE-METHOD 是一个函数,这个函数需要两个数字参数,代表
   ;; 保存一下用户选择过的词生成的缓存和词频缓存,
   ;; 因为使用 async 机制更新 dcache 时,需要从 dcache 文件
   ;; 中读取变量值, 然后再对用户选择过的词生成的缓存排序,如果没
-  ;; 有这一步骤,导入的词条就会被覆盖,使用 emacs-thread 机制来更新 dcache
-  ;; 不存在此问题。
-  (unless pyim-dcache-prefer-emacs-thread
-    (pyim-dcache-save-caches))
+  ;; 有这一步骤,导入的词条就会被覆盖。
+  (pyim-dcache-save-caches)
   ;; 更新相关的 dcache
   (pyim-dcache-call-api 'update-personal-words t)
 
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 76bf367..7f04527 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -80,61 +80,39 @@
 如果 FORCE 为真,强制加载缓存。"
   (interactive)
   (when (or force (not pyim-dhashcache-update-ishortcode2word))
-    (if (pyim-dcache-use-emacs-thread-p)
-        (make-thread
-         `(lambda ()
-            (maphash
-             (lambda (key value)
-               (let ((newkey (mapconcat
-                              (lambda (x)
-                                (substring x 0 1))
-                              (split-string key "-") "-")))
-                 (puthash newkey
-                          (delete-dups
-                           `(,@value
-                             ,@(gethash newkey 
pyim-dhashcache-ishortcode2word)))
-                          pyim-dhashcache-ishortcode2word)))
-             pyim-dhashcache-icode2word)
-            (maphash
-             (lambda (key value)
-               (puthash key (pyim-dhashcache-sort-words value)
-                        pyim-dhashcache-ishortcode2word))
-             pyim-dhashcache-ishortcode2word)
-            (pyim-dcache-save-variable 'pyim-dhashcache-ishortcode2word)
-            (setq pyim-dhashcache-update-ishortcode2word t)))
-      (async-start
-       `(lambda ()
-          ,(async-inject-variables "^load-path$")
-          ,(async-inject-variables "^exec-path$")
-          ,(async-inject-variables "^pyim-.+?directory$")
-          (require 'pyim-dhashcache)
-          (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
-          (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
-          (setq pyim-dhashcache-ishortcode2word
-                (make-hash-table :test #'equal))
-          (maphash
-           (lambda (key value)
-             (when (and (> (length key) 0)
-                        (not (string-match-p "[^a-z-]" key)))
-               (let* ((newkey (mapconcat
-                               (lambda (x)
-                                 (substring x 0 1))
-                               (split-string key "-") "-")))
-                 (puthash newkey
-                          (delete-dups
-                           `(,@value
-                             ,@(gethash newkey 
pyim-dhashcache-ishortcode2word)))
-                          pyim-dhashcache-ishortcode2word))))
-           pyim-dhashcache-icode2word)
-          (maphash
-           (lambda (key value)
-             (puthash key (pyim-dhashcache-sort-words value)
-                      pyim-dhashcache-ishortcode2word))
-           pyim-dhashcache-ishortcode2word)
-          (pyim-dcache-save-variable 'pyim-dhashcache-ishortcode2word))
-       `(lambda (result)
-          (setq pyim-dhashcache-update-ishortcode2word t)
-          (pyim-dcache-set-variable 'pyim-dhashcache-ishortcode2word t))))))
+    (async-start
+     `(lambda ()
+        ,(async-inject-variables "^load-path$")
+        ,(async-inject-variables "^exec-path$")
+        ,(async-inject-variables "^pyim-.+?directory$")
+        (require 'pyim-dhashcache)
+        (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
+        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (setq pyim-dhashcache-ishortcode2word
+              (make-hash-table :test #'equal))
+        (maphash
+         (lambda (key value)
+           (when (and (> (length key) 0)
+                      (not (string-match-p "[^a-z-]" key)))
+             (let* ((newkey (mapconcat
+                             (lambda (x)
+                               (substring x 0 1))
+                             (split-string key "-") "-")))
+               (puthash newkey
+                        (delete-dups
+                         `(,@value
+                           ,@(gethash newkey pyim-dhashcache-ishortcode2word)))
+                        pyim-dhashcache-ishortcode2word))))
+         pyim-dhashcache-icode2word)
+        (maphash
+         (lambda (key value)
+           (puthash key (pyim-dhashcache-sort-words value)
+                    pyim-dhashcache-ishortcode2word))
+         pyim-dhashcache-ishortcode2word)
+        (pyim-dcache-save-variable 'pyim-dhashcache-ishortcode2word))
+     `(lambda (result)
+        (setq pyim-dhashcache-update-ishortcode2word t)
+        (pyim-dcache-set-variable 'pyim-dhashcache-ishortcode2word t)))))
 
 (defun pyim-dhashcache-update-shortcode2word (&optional force)
   "使用 `pyim-dhashcache-code2word' 中的词条,创建简写 code 词库缓存并加载.
@@ -142,65 +120,43 @@
 如果 FORCE 为真,强制运行。"
   (interactive)
   (when (or force (not pyim-dhashcache-update-shortcode2word))
-    (if (pyim-dcache-use-emacs-thread-p)
-        (make-thread
-         `(lambda ()
-            (maphash
-             (lambda (key value)
-               (dolist (x (pyim-dhashcache-get-shortcode key))
-                 (puthash x
-                          (mapcar
-                           (lambda (word)
-                             (if (get-text-property 0 :comment word)
-                                 word
-                               (propertize word :comment (substring key 
(length x)))))
-                           (delete-dups `(,@value ,@(gethash x 
pyim-dhashcache-shortcode2word))))
-                          pyim-dhashcache-shortcode2word)))
-             pyim-dhashcache-code2word)
-            (maphash
-             (lambda (key value)
-               (puthash key (pyim-dhashcache-sort-words value)
-                        pyim-dhashcache-shortcode2word))
-             pyim-dhashcache-shortcode2word)
-            (pyim-dcache-save-variable 'pyim-dhashcache-shortcode2word)
-            (setq pyim-dhashcache-update-shortcode2word t)))
-      (async-start
-       `(lambda ()
-          ,(async-inject-variables "^load-path$")
-          ,(async-inject-variables "^exec-path$")
-          ,(async-inject-variables "^pyim-.+?directory$")
-          (require 'pyim-dhashcache)
-          (pyim-dcache-set-variable 'pyim-dhashcache-code2word)
-          (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
-          (setq pyim-dhashcache-shortcode2word
-                (make-hash-table :test #'equal))
-          (maphash
-           (lambda (key value)
-             (dolist (x (pyim-dhashcache-get-shortcode key))
-               (puthash x
-                        (mapcar
-                         (lambda (word)
-                           ;; 这个地方的代码用于实现五笔 code 自动提示功能,
-                           ;; 比如输入 'aa' 后得到选词框:
-                           ;; ----------------------
-                           ;; | 1. 莁aa 2.匶wv ... |
-                           ;; ----------------------
-                           (if (get-text-property 0 :comment word)
-                               word
-                             (propertize word :comment (substring key (length 
x)))))
-                         (delete-dups `(,@value ,@(gethash x 
pyim-dhashcache-shortcode2word))))
-                        pyim-dhashcache-shortcode2word)))
-           pyim-dhashcache-code2word)
-          (maphash
-           (lambda (key value)
-             (puthash key (pyim-dhashcache-sort-words value)
-                      pyim-dhashcache-shortcode2word))
-           pyim-dhashcache-shortcode2word)
-          (pyim-dcache-save-variable 'pyim-dhashcache-shortcode2word)
-          nil)
-       `(lambda (result)
-          (setq pyim-dhashcache-update-shortcode2word t)
-          (pyim-dcache-set-variable 'pyim-dhashcache-shortcode2word t))))))
+    (async-start
+     `(lambda ()
+        ,(async-inject-variables "^load-path$")
+        ,(async-inject-variables "^exec-path$")
+        ,(async-inject-variables "^pyim-.+?directory$")
+        (require 'pyim-dhashcache)
+        (pyim-dcache-set-variable 'pyim-dhashcache-code2word)
+        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (setq pyim-dhashcache-shortcode2word
+              (make-hash-table :test #'equal))
+        (maphash
+         (lambda (key value)
+           (dolist (x (pyim-dhashcache-get-shortcode key))
+             (puthash x
+                      (mapcar
+                       (lambda (word)
+                         ;; 这个地方的代码用于实现五笔 code 自动提示功能,
+                         ;; 比如输入 'aa' 后得到选词框:
+                         ;; ----------------------
+                         ;; | 1. 莁aa 2.匶wv ... |
+                         ;; ----------------------
+                         (if (get-text-property 0 :comment word)
+                             word
+                           (propertize word :comment (substring key (length 
x)))))
+                       (delete-dups `(,@value ,@(gethash x 
pyim-dhashcache-shortcode2word))))
+                      pyim-dhashcache-shortcode2word)))
+         pyim-dhashcache-code2word)
+        (maphash
+         (lambda (key value)
+           (puthash key (pyim-dhashcache-sort-words value)
+                    pyim-dhashcache-shortcode2word))
+         pyim-dhashcache-shortcode2word)
+        (pyim-dcache-save-variable 'pyim-dhashcache-shortcode2word)
+        nil)
+     `(lambda (result)
+        (setq pyim-dhashcache-update-shortcode2word t)
+        (pyim-dcache-set-variable 'pyim-dhashcache-shortcode2word t)))))
 
 (defun pyim-dhashcache-get-path (variable)
   "获取保存 VARIABLE 取值的文件的路径."
@@ -270,26 +226,18 @@ DCACHE 是一个 code -> words 的 hashtable.
          (code2word-md5-file (pyim-dhashcache-get-path 
'pyim-dhashcache-code2word-md5)))
     (when (or force (not (equal dicts-md5 (pyim-dcache-get-value-from-file 
code2word-md5-file))))
       ;; use hashtable
-      (if (pyim-dcache-use-emacs-thread-p)
-          (make-thread
-           `(lambda ()
-              (let ((dcache (pyim-dhashcache-generate-dcache-file ',dict-files 
,code2word-file)))
-                (pyim-dhashcache-generate-word2code-dcache-file dcache 
,word2code-file))
-              (pyim-dcache-save-value-to-file ',dicts-md5 ,code2word-md5-file)
-              (pyim-dcache-set-variable 'pyim-dhashcache-code2word t)
-              (pyim-dcache-set-variable 'pyim-dhashcache-word2code t)))
-        (async-start
-         `(lambda ()
-            ,(async-inject-variables "^load-path$")
-            ,(async-inject-variables "^exec-path$")
-            ,(async-inject-variables "^pyim-.+?directory$")
-            (require 'pyim-dhashcache)
-            (let ((dcache (pyim-dhashcache-generate-dcache-file ',dict-files 
,code2word-file)))
-              (pyim-dhashcache-generate-word2code-dcache-file dcache 
,word2code-file))
-            (pyim-dcache-save-value-to-file ',dicts-md5 ,code2word-md5-file))
-         `(lambda (result)
-            (pyim-dcache-set-variable 'pyim-dhashcache-code2word t)
-            (pyim-dcache-set-variable 'pyim-dhashcache-word2code t)))))))
+      (async-start
+       `(lambda ()
+          ,(async-inject-variables "^load-path$")
+          ,(async-inject-variables "^exec-path$")
+          ,(async-inject-variables "^pyim-.+?directory$")
+          (require 'pyim-dhashcache)
+          (let ((dcache (pyim-dhashcache-generate-dcache-file ',dict-files 
,code2word-file)))
+            (pyim-dhashcache-generate-word2code-dcache-file dcache 
,word2code-file))
+          (pyim-dcache-save-value-to-file ',dicts-md5 ,code2word-md5-file))
+       `(lambda (result)
+          (pyim-dcache-set-variable 'pyim-dhashcache-code2word t)
+          (pyim-dcache-set-variable 'pyim-dhashcache-word2code t))))))
 
 (defun pyim-dhashcache-export (dcache file &optional confirm)
   "将一个 pyim DCACHE 导出为文件 FILE.
@@ -340,34 +288,24 @@ code 对应的中文词条了。
 如果 FORCE 为真,强制排序。"
   (interactive)
   (when (or force (not pyim-dhashcache-update-icode2word-p))
-    (if (pyim-dcache-use-emacs-thread-p)
-        (make-thread
-         `(lambda ()
-            (maphash
-             (lambda (key value)
-               (puthash key (pyim-dhashcache-sort-words value)
-                        pyim-dhashcache-icode2word))
-             pyim-dhashcache-icode2word)
-            (pyim-dcache-save-variable 'pyim-dhashcache-icode2word)
-            (setq pyim-dhashcache-update-icode2word-p t)))
-      (async-start
-       `(lambda ()
-          ,(async-inject-variables "^load-path$")
-          ,(async-inject-variables "^exec-path$")
-          ,(async-inject-variables "^pyim-.+?directory$")
-          (require 'pyim-dhashcache)
-          (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
-          (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
-          (maphash
-           (lambda (key value)
-             (puthash key (pyim-dhashcache-sort-words value)
-                      pyim-dhashcache-icode2word))
-           pyim-dhashcache-icode2word)
-          (pyim-dcache-save-variable 'pyim-dhashcache-icode2word)
-          nil)
-       `(lambda (result)
-          (setq pyim-dhashcache-update-icode2word-p t)
-          (pyim-dcache-set-variable 'pyim-dhashcache-icode2word t))))))
+    (async-start
+     `(lambda ()
+        ,(async-inject-variables "^load-path$")
+        ,(async-inject-variables "^exec-path$")
+        ,(async-inject-variables "^pyim-.+?directory$")
+        (require 'pyim-dhashcache)
+        (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
+        (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
+        (maphash
+         (lambda (key value)
+           (puthash key (pyim-dhashcache-sort-words value)
+                    pyim-dhashcache-icode2word))
+         pyim-dhashcache-icode2word)
+        (pyim-dcache-save-variable 'pyim-dhashcache-icode2word)
+        nil)
+     `(lambda (result)
+        (setq pyim-dhashcache-update-icode2word-p t)
+        (pyim-dcache-set-variable 'pyim-dhashcache-icode2word t)))))
 
 (defun pyim-dhashcache-update-personal-words (&optional force)
   (pyim-dhashcache-update-icode2word force)



reply via email to

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