Revision: 7270
Author:   deton.kih
Date:     Thu Aug 18 04:19:07 2011
Log:      * scm/tutcode.scm
  - (tutcode-bushu-decompose,
     tutcode-rule->reverse-hash-table,
     tutcode-reverse-find-seq):
    Change to use kanji code as hash-table key for performance.
  - (tutcode-euc-jp-string->ichar):
    New function to get kanji code from EUC-JP string.

http://code.google.com/p/uim/source/detail?r=7270

Modified:
 /trunk/scm/tutcode.scm

=======================================
--- /trunk/scm/tutcode.scm      Thu Aug 18 04:16:49 2011
+++ /trunk/scm/tutcode.scm      Thu Aug 18 04:19:07 2011
@@ -4017,7 +4017,9 @@
   (if (null? tutcode-reverse-bushudic-hash-table)
     (set! tutcode-reverse-bushudic-hash-table
       (tutcode-rule->reverse-hash-table tutcode-bushudic)))
-  (hash-table-ref/default tutcode-reverse-bushudic-hash-table c #f))
+  (let ((i (tutcode-euc-jp-string->ichar c)))
+    (and i
+      (hash-table-ref/default tutcode-reverse-bushudic-hash-table i #f))))

 ;;; tutcode-rule·Á¼°¤Î¥ê¥¹¥È¤«¤é¡¢µÕ°ú¤­¸¡º÷(´Á»ú¤«¤éÂǸ°¥ê¥¹¥È¤ò¼èÆÀ)ÍѤÎ
 ;;; hash-table¤òºî¤ë
@@ -4027,10 +4029,28 @@
   (alist->hash-table
     (filter-map
       (lambda (elem)
-        (and (string? (caadr elem)) ; 'tutcode-mazegaki-startÅù¤Ï½ü¤¯
-          (cons (caadr elem) (caar elem))))
-      rule)
-    string=?))
+        (and-let*
+          ((kanji (caadr elem))
+ (kanji-string? (string? kanji)) ; 'tutcode-mazegaki-startÅù¤Ï½ü¤¯
+           (i (tutcode-euc-jp-string->ichar kanji)))
+          (cons i (caar elem))))
+      rule)))
+
+;;; hash-table¤Î¥­¡¼ÍѤˡ¢´Á»ú1ʸ»ú¤Îʸ»úÎ󤫤é´Á»ú¥³¡¼¥É¤ËÊÑ´¹¤¹¤ë
+;;; @param s ʸ»úÎó
+;;; @return ´Á»ú¥³¡¼¥É¡£Ê¸»úÎó¤ÎŤµ¤¬1¤Ç¤Ê¤¤¾ì¹ç¤Ï#f
+(define (tutcode-euc-jp-string->ichar s)
+  ;; ichar.scm¤Îstring->ichar(string->charcode)¤ÎEUC-JPÈÇ
+  (let ((sl (with-char-codec "EUC-JP"
+              (lambda ()
+                (string->list s)))))
+    (cond
+      ((null? sl)
+        0)
+      ((null? (cdr sl))
+        (char->integer (car sl)))
+      (else
+        #f))))

;;; ¼«Æ°¥Ø¥ë¥×:bushu.help¥Õ¥¡¥¤¥ë¤ò¸¡º÷¤·¤ÆÂоÝʸ»ú¤Î¥Ø¥ë¥×(2¤Ä¤ÎÉô¼ó)¤ò¼èÆÀ¤¹¤ë
 ;;; @param c ÂоÝʸ»ú
@@ -4336,8 +4356,10 @@
             (if (null? tutcode-reverse-rule-hash-table)
               (set! tutcode-reverse-rule-hash-table
                 (tutcode-rule->reverse-hash-table rule)))
-            tutcode-reverse-rule-hash-table))))
-       (hash-table-ref/default hash-table c #f))))
+            tutcode-reverse-rule-hash-table)))
+       (i (tutcode-euc-jp-string->ichar c)))
+      (and i
+        (hash-table-ref/default hash-table i #f)))))

 ;;; ¸½ºß¤Îstate¤¬preedit¤ò»ý¤Ä¤«¤É¤¦¤«¤òÊÖ¤¹¡£
 ;;; @param pc ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È

Reply via email to