emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: Some mule-unicode-* characters are incorrectly displayed with fontse


From: YAMAMOTO Mitsuharu
Subject: Re: Some mule-unicode-* characters are incorrectly displayed with fontset-mac
Date: Thu, 16 Jan 2003 11:45:40 +0900
User-agent: Wanderlust/2.10.0 (Venus) SEMI/1.14.3 (Ushinoya) FLIM/1.14.4 (Kashiharajingū-mae) APEL/10.3 Emacs/21.3.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Wed, 15 Jan 2003 15:02:03 +0900 (JST), Kenichi Handa <address@hidden> 
>>>>> said:

>> 2. use the char-table for decoding instead of that for encoding.
> I think 2. is a better fix because it's a little bit faster.  I've
> just installed it.
>> As for the fix 1 above, a similar problem can be found in
>> `optimize-char-coding-system-table' in lisp/international/mule.el.
> Yes.  I've also changed it along your suggestion.

Thanks for the changes.

>> As far as I know, most of the uses of `char-map-table' essentially
>> operate only on entries having non-nil (or non-default?) values.
>> How about adding some option to control the behavior of
>> `char-map-table' so that we can reduce the overhead of needless
>> function calls?
> Even if we add that option, without modifying the codes that use
> char-map-table, there's no effect.  And, if we are going to modify
> them, we can modify them as (if val ...).  So, I'm negative to that
> change.

In fact, I was thinking about even changing the default behavior so as
not to traverse nil-valued characters because they are usually
explicitly excluded (sometimes forgot to be excluded), and that leads
to some overhead of the needless function calls.  But that is an
incompatible change and I could not tell how many existing codes are
affected by such a change.  So I mentioned ``adding option''.  Anyway,
I don't have enough reasons to insist that such a change should be
done.

By the way, besides the change of `optimize-char-coding-system-table',
I was trying to reduce the startup time when customizing
`utf-translate-cjk' to `t'.  The idea is to eliminate intermediate
data structures in `register-char-codings' by

  1. allowing a list of coding systems as well as a single coding
     system for the first argument `coding-system';
  2. allowing a hash table as well as a char table for the second
     argument `safe-chars';
  3. reusing the previous result of the addition of coding systems if
     possible.

(defun register-char-codings (coding-system safe-chars)
  "Add entries for CODING-SYSTEM to `char-coding-system-table'.
If SAFE-CHARS is a char-table, its non-nil entries specify characters
which CODING-SYSTEM encodes safely.  If SAFE-CHARS is t, register
CODING-SYSTEM as a general one which can encode all characters."
  (if (not (listp coding-system))
      (setq coding-system (list coding-system)))
  (let ((general (char-table-extra-slot char-coding-system-table 0))
        ;; Charsets which have some members in the table, but not all
        ;; of them (i.e. not just a generic character):
        (partials (char-table-extra-slot char-coding-system-table 1)))
    (if (eq safe-chars t)
        (dolist (coding coding-system)
          (or (memq coding general)
              (set-char-table-extra-slot char-coding-system-table 0
                                         (cons coding general))))
      (let ((prev-codings nil)
            (cached-codings coding-system))
        (funcall
         (if (char-table-p safe-chars) 'map-char-table 'maphash)
         (lambda (key val)
           (if (and (>= key 128) val)
               (let ((codings (aref char-coding-system-table key))
                     (charset (char-charset key)))
                 (if (and (generic-char-p key)
                          (memq charset partials))
                     (let (new-codings entry existing)
                       (dolist (coding coding-system)
                         (unless (memq coding-system codings)
                           (push coding new-codings)))
                       (when new-codings
                         ;; The generic char would clobber individual
                         ;; entries already in the table.  First save the
                         ;; separate existing entries for all chars of the
                         ;; charset (with the generic entry added, if
                         ;; necessary).
                         (map-charset-chars
                          (lambda (start end)
                            (while (<= start end)
                              (setq entry
                                    (aref char-coding-system-table start))
                              (when entry
                                (unless (eq entry prev-codings)
                                  (setq prev-codings entry)
                                  (setq cached-codings prev-codings)
                                  (dolist (coding new-codings)
                                    (unless (memq coding entry)
                                      (push coding cached-codings))))
                                (push (cons start cached-codings) existing))
                              (setq start (1+ start))))
                          charset)
                         ;; Update the generic entry.
                         (aset char-coding-system-table key
                               (nconc new-codings codings))
                         ;; Override with the saved entries.
                         (dolist (elt existing)
                           (aset char-coding-system-table
                                 (car elt) (cdr elt)))))
                   (unless (eq codings prev-codings)
                     (setq prev-codings codings)
                     (setq cached-codings prev-codings)
                     (dolist (coding coding-system)
                       (unless (memq coding codings)
                         (push coding cached-codings))))
                   (aset char-coding-system-table key cached-codings)
                   (unless (or (memq charset partials)
                               (generic-char-p key))
                     (push charset partials))))))
         safe-chars))
      ;; This is probably too expensive (e.g. multiple calls in
      ;; ucs-tables), and only really relevant in certain cases, so do
      ;; it explicitly where appropriate.
      ;; (optimize-char-coding-system-table)
      (set-char-table-extra-slot char-coding-system-table 1 partials))))



*** utf-8.el.~1.23.~    Sat Jan  4 11:02:21 2003
--- utf-8.el    Thu Jan 16 00:03:24 2003
***************
*** 254,266 ****
                 (load "subst-gb2312")
                 (load "subst-big5")
                 (load "subst-jis")))   ; jis covers as much as big5, gb2312
!              (let ((table (make-char-table 'translation-table)))
!                (maphash (lambda (k v)
!                           (aset table k t))
!                         ucs-mule-cjk-to-unicode)
!                (register-char-codings 'mule-utf-8 table)
!                (register-char-codings 'mule-utf-16-le table)
!                (register-char-codings 'mule-utf-16-be table))
               (define-translation-hash-table 'utf-subst-table-for-decode
                 ucs-unicode-to-mule-cjk)
               (define-translation-hash-table 'utf-subst-table-for-encode
--- 254,262 ----
                 (load "subst-gb2312")
                 (load "subst-big5")
                 (load "subst-jis")))   ; jis covers as much as big5, gb2312
!              (register-char-codings
!               '(mule-utf-8 mule-utf-16-le mule-utf-16-be)
!               ucs-mule-cjk-to-unicode)
               (define-translation-hash-table 'utf-subst-table-for-decode
                 ucs-unicode-to-mule-cjk)
               (define-translation-hash-table 'utf-subst-table-for-encode

This prototype shows the following difference in the execution time of
`register-char-codings' when we customize `utf-translate-cjk' to `t':

Original:
Function Name                      Call Count  Elapsed Time  Average Time
=================================  ==========  ============  ============
register-char-codings              3           2.714739      0.904913

Prototype:
Function Name                      Call Count  Elapsed Time  Average Time
=================================  ==========  ============  ============
register-char-codings              1           0.590429      0.590429

Further speedup could be possible if we replace `mapc' with `dolist'
in lisp/international/subst-*.el, and byte compile the setfunction of
`utf-translate-cjk' (i.e., :set field in (defcustom utf-translate-cjk
...).  Currently, it is not byte compiled in utf-8.elc) in utf-8.el.
But they are not so significant as the above changes.

                                     YAMAMOTO Mitsuharu
                                address@hidden




reply via email to

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