all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Kenichi Handa <handa@m17n.org>
Cc: cyd@stupidchicken.com, emacs-devel@gnu.org
Subject: Re: faster unicode character name completion
Date: Mon, 07 Dec 2009 09:57:46 -0500	[thread overview]
Message-ID: <jwvk4wyj22f.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <tl7ocmbbl12.fsf@m17n.org> (Kenichi Handa's message of "Mon, 07 Dec 2009 11:00:41 +0900")

>> > (defun ucs-name-completion (str)
>> >   (when (string-match "^[A-Za-z]*" str)
>> >     (let ((head (match-string 0 str))
>> > 	  slot names)
>> >       (if (and (= (length head) (length str))
>> > 	       (not (assoc-string str ucs-name-head-table)))
>> > 	  (ucs-name-filter str ucs-name-head-table)
>> > 	(ucs-name-filter str (ucs-name-expand-table head))))))

>> I don't understand what ucs-name-filter is trying to do.

> ?? It simply filters out elements that doesn't match with
> STR from NAMES (alist).

But then why is it needed?
Doesn't `completion-table-dynamic' take care of that already?

BTW, I tried the "precompute the table and autoload it" approach, and it
works fine in the sense that it's fast.  The generated file is about
1.3MB.  Basically, the main downside of this approach is that it doesn't
use the very strings we already have for the names, so after loading it
we have 2 copies of every char name in memory.

But I have a better idea: most of the time is not spent building the
completion table, but rather just weeding out all the "chars" that don't
have names, or should I say, looking for the few rare chars that do
have a name.

So the patch below seems to eb a good compromise: it uses up just about
1000K cons cells (i.e. 16KB on 64bit systems) to keep the precomputed
set of ~34K chars that do have a name, so that building the completion
table takes only a couple seconds.


        Stefan


--- mule-cmds.el.~1.383.~	2009-11-11 21:01:36.000000000 -0500
+++ mule-cmds.el	2009-12-07 09:55:16.000000000 -0500
@@ -2883,6 +2883,31 @@
 (defvar nonascii-insert-offset 0 "This variable is obsolete.")
 (defvar nonascii-translation-table nil "This variable is obsolete.")
 
+(defvar ucs-named-char-ranges
+  (purecopy
+   (eval-when-compile
+     (let ((ranges ())
+           (first 0)
+           (last 0))
+       (dotimes-with-progress-reporter (c #xEFFFF)
+           "Loading Unicode character names..."
+         (unless (or
+                  (and (>= c #x3400 ) (<= c #x4dbf )) ; CJK Ideograph Extension Arch
+                  (and (>= c #x4e00 ) (<= c #x9fff )) ; CJK Ideograph
+                  (and (>= c #xd800 ) (<= c #xfaff )) ; Private/Surrogate
+                  (and (>= c #x20000) (<= c #x2ffff)) ; CJK Ideograph Extensions B, C
+                  (null (get-char-code-property c 'name)))
+           ;; This char has a name.
+           (if (<= c (1+ last))
+               ;; Extend the current range.
+               (setq last c)
+             ;; We have to split the range.
+             (push (cons first last) ranges)
+             (setq first (setq last c)))))
+       (cons (cons first last) ranges))))
+  "List of ranges of chars that have names.
+Every range is of the form (FIRST . LAST).")
+
 (defvar ucs-names nil
   "Alist of cached (CHAR-NAME . CHAR-CODE) pairs.")
 
@@ -2891,18 +2916,16 @@
   (or ucs-names
       (setq ucs-names
 	    (let (name names)
-	      (dotimes-with-progress-reporter (c #xEFFFF)
-		  "Loading Unicode character names..."
-		(unless (or
-			 (and (>= c #x3400 ) (<= c #x4dbf )) ; CJK Ideograph Extension A
-			 (and (>= c #x4e00 ) (<= c #x9fff )) ; CJK Ideograph
-			 (and (>= c #xd800 ) (<= c #xfaff )) ; Private/Surrogate
-			 (and (>= c #x20000) (<= c #x2ffff)) ; CJK Ideograph Extensions B, C
-			 )
+              (dolist (range ucs-named-char-ranges)
+                (let ((c (car range))
+                      (end (cdr range)))
+                  (while (<= c end)
 		  (if (setq name (get-char-code-property c 'name))
-		      (setq names (cons (cons name c) names)))
+                        (setq names (cons (cons name c) names))
+                      (error "Wrong range"))
 		  (if (setq name (get-char-code-property c 'old-name))
-		      (setq names (cons (cons name c) names)))))
+                        (setq names (cons (cons name c) names)))
+                    (setq c (1+ c)))))
 	      names))))
 
 (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names)




  parent reply	other threads:[~2009-12-07 14:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-30 19:55 Emacs 23.2 pretest freeze? Karl Fogel
2009-11-30 22:48 ` Chong Yidong
2009-11-30 23:05   ` Karl Fogel
2009-12-02 13:34   ` Alan Mackenzie
2009-12-03 21:35 ` Emacs 23.2 Pretest next week Chong Yidong
2009-12-04 11:23   ` faster unicode character name completion Kenichi Handa
2009-12-04 12:08     ` Deniz Dogan
2009-12-04 13:04     ` Juanma Barranquero
2009-12-04 13:26     ` Florian Beck
2009-12-04 15:07     ` Stefan Monnier
2009-12-04 22:38       ` Miles Bader
2009-12-07  2:00       ` Kenichi Handa
2009-12-07  8:13         ` Kenichi Handa
2009-12-07 14:57         ` Stefan Monnier [this message]
2009-12-07 20:28           ` Juri Linkov
2009-12-07 21:42             ` Stefan Monnier
2009-12-08  1:59               ` Miles Bader
2009-12-08  1:45           ` Kenichi Handa
2009-12-08  2:29             ` Stefan Monnier
2009-12-09  0:12             ` Chong Yidong
2009-12-09  0:57               ` Kenichi Handa
2009-12-09  9:02                 ` Deniz Dogan
2009-12-04 19:04   ` Emacs 23.2 Pretest next week Dan Nicolaescu
2009-12-04 21:15     ` Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvk4wyj22f.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=handa@m17n.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.