diff options
| author | Stefan Monnier | 2009-12-07 16:12:47 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-12-07 16:12:47 +0000 |
| commit | da10ce2bb0f64bbbd62f49756952f19a37453d65 (patch) | |
| tree | e4abdbc5768919a1c6d17a759656c16182433b0b | |
| parent | 3d68fa99af7a4b84b2fdc44b429b9cddcbaaf88c (diff) | |
| download | emacs-da10ce2bb0f64bbbd62f49756952f19a37453d65.tar.gz emacs-da10ce2bb0f64bbbd62f49756952f19a37453d65.zip | |
(ucs-names): Weed out at compile-time the chars that don't have names, so
the table can be built much faster at run-time.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/international/mule-cmds.el | 57 |
2 files changed, 48 insertions, 15 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 72be092c851..f633d7a1275 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2009-12-07 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * international/mule-cmds.el (ucs-names): Weed out at compile-time the | ||
| 4 | chars that don't have names, so the table can be built much faster at | ||
| 5 | run-time. | ||
| 6 | |||
| 1 | 2009-12-07 Chong Yidong <cyd@stupidchicken.com> | 7 | 2009-12-07 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * simple.el (compose-mail): Check for incompatibilities and warn. | 9 | * simple.el (compose-mail): Check for incompatibilities and warn. |
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index ad1e3b7f538..57060ff9442 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el | |||
| @@ -2889,21 +2889,48 @@ on encoding." | |||
| 2889 | (defun ucs-names () | 2889 | (defun ucs-names () |
| 2890 | "Return alist of (CHAR-NAME . CHAR-CODE) pairs cached in `ucs-names'." | 2890 | "Return alist of (CHAR-NAME . CHAR-CODE) pairs cached in `ucs-names'." |
| 2891 | (or ucs-names | 2891 | (or ucs-names |
| 2892 | (setq ucs-names | 2892 | (let ((ranges |
| 2893 | (let (name names) | 2893 | (purecopy |
| 2894 | (dotimes-with-progress-reporter (c #xEFFFF) | 2894 | ;; We precompute at compile-time the ranges of chars |
| 2895 | "Loading Unicode character names..." | 2895 | ;; that have names, so that at runtime, building the |
| 2896 | (unless (or | 2896 | ;; table can be done faster, since most of the time is |
| 2897 | (and (>= c #x3400 ) (<= c #x4dbf )) ; CJK Ideograph Extension A | 2897 | ;; spent looking for the chars that do have a name. |
| 2898 | (and (>= c #x4e00 ) (<= c #x9fff )) ; CJK Ideograph | 2898 | (eval-when-compile |
| 2899 | (and (>= c #xd800 ) (<= c #xfaff )) ; Private/Surrogate | 2899 | (let ((ranges ()) |
| 2900 | (and (>= c #x20000) (<= c #x2ffff)) ; CJK Ideograph Extensions B, C | 2900 | (first 0) |
| 2901 | ) | 2901 | (last 0)) |
| 2902 | (if (setq name (get-char-code-property c 'name)) | 2902 | (dotimes-with-progress-reporter (c #xEFFFF) |
| 2903 | (setq names (cons (cons name c) names))) | 2903 | "Finding Unicode characters with names..." |
| 2904 | (if (setq name (get-char-code-property c 'old-name)) | 2904 | (unless (or |
| 2905 | (setq names (cons (cons name c) names))))) | 2905 | ;; CJK Ideograph Extension Arch |
| 2906 | names)))) | 2906 | (and (>= c #x3400 ) (<= c #x4dbf )) |
| 2907 | ;; CJK Ideograph | ||
| 2908 | (and (>= c #x4e00 ) (<= c #x9fff )) | ||
| 2909 | ;; Private/Surrogate | ||
| 2910 | (and (>= c #xd800 ) (<= c #xfaff )) | ||
| 2911 | ;; CJK Ideograph Extensions B, C | ||
| 2912 | (and (>= c #x20000) (<= c #x2ffff)) | ||
| 2913 | (null (get-char-code-property c 'name))) | ||
| 2914 | ;; This char has a name. | ||
| 2915 | (if (<= c (1+ last)) | ||
| 2916 | ;; Extend the current range. | ||
| 2917 | (setq last c) | ||
| 2918 | ;; We have to split the range. | ||
| 2919 | (push (cons first last) ranges) | ||
| 2920 | (setq first (setq last c))))) | ||
| 2921 | (cons (cons first last) ranges)))) | ||
| 2922 | name names) | ||
| 2923 | (dolist (range ranges) | ||
| 2924 | (let ((c (car range)) | ||
| 2925 | (end (cdr range))) | ||
| 2926 | (while (<= c end) | ||
| 2927 | (if (setq name (get-char-code-property c 'name)) | ||
| 2928 | (push (cons name c) names) | ||
| 2929 | (error "Wrong range")) | ||
| 2930 | (if (setq name (get-char-code-property c 'old-name)) | ||
| 2931 | (push (cons name c) names)) | ||
| 2932 | (setq c (1+ c))))) | ||
| 2933 | (setq ucs-names names))))) | ||
| 2907 | 2934 | ||
| 2908 | (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names) | 2935 | (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names) |
| 2909 | "Lazy completion table for completing on Unicode character names.") | 2936 | "Lazy completion table for completing on Unicode character names.") |