Mercurial > hg > xemacs-beta
comparison lisp/mule/mule-charset.el @ 1309:00abb1091204
[xemacs-hg @ 2003-02-17 14:50:55 by stephent]
charsets-in-region optimization <874r73qa2b.fsf@tleepslib.sk.tsukuba.ac.jp>
wid-edit.el synch <87znovote9.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Mon, 17 Feb 2003 14:51:02 +0000 |
parents | f770374ae506 |
children | ce294639d321 |
comparison
equal
deleted
inserted
replaced
1308:1741c7ce4ac0 | 1309:00abb1091204 |
---|---|
36 | 36 |
37 ;;; Code: | 37 ;;; Code: |
38 | 38 |
39 ;;;; Classifying text according to charsets | 39 ;;;; Classifying text according to charsets |
40 | 40 |
41 ;; the old version was broken in a couple of ways | |
42 ;; this is one of several versions, I tried a hash as well as the | |
43 ;; `prev-charset' cache used in the old version, but this was definitely | |
44 ;; faster than the hash version and marginally faster than the prev-charset | |
45 ;; version | |
46 ;; #### this really needs to be moved into C | |
41 (defun charsets-in-region (start end &optional buffer) | 47 (defun charsets-in-region (start end &optional buffer) |
42 "Return a list of the charsets in the region between START and END. | 48 "Return a list of the charsets in the region between START and END. |
43 BUFFER defaults to the current buffer if omitted." | 49 BUFFER defaults to the current buffer if omitted." |
44 (let (list) | 50 (let (list) |
45 (save-excursion | 51 (save-excursion |
47 (set-buffer buffer)) | 53 (set-buffer buffer)) |
48 (save-restriction | 54 (save-restriction |
49 (narrow-to-region start end) | 55 (narrow-to-region start end) |
50 (goto-char (point-min)) | 56 (goto-char (point-min)) |
51 (while (not (eobp)) | 57 (while (not (eobp)) |
52 (let* (prev-charset | 58 ;; the first test will usually succeed on testing the |
53 (ch (char-after (point))) | 59 ;; car of the list; don't waste time let-binding. |
54 (charset (char-charset ch))) | 60 (or (memq (char-charset (char-after (point))) list) |
55 (if (not (eq prev-charset charset)) | 61 (setq list (cons (char-charset (char-after (point))) list))) |
56 (progn | |
57 (setq prev-charset charset) | |
58 (or (memq charset list) | |
59 (setq list (cons charset list)))))) | |
60 (forward-char)))) | 62 (forward-char)))) |
61 list)) | 63 list)) |
62 | 64 |
63 (defun charsets-in-string (string) | 65 (defun charsets-in-string (string) |
64 "Return a list of the charsets in STRING." | 66 "Return a list of the charsets in STRING." |
65 (let ((i 0) | 67 (let (list) |
66 (len (length string)) | 68 (mapc (lambda (ch) |
67 prev-charset charset list) | 69 ;; the first test will usually succeed on testing the |
68 (while (< i len) | 70 ;; car of the list; don't waste time let-binding. |
69 (setq charset (char-charset (aref string i))) | 71 (or (memq (char-charset ch) list) |
70 (if (not (eq prev-charset charset)) | 72 (setq list (cons (char-charset ch) list)))) |
71 (progn | 73 string) |
72 (setq prev-charset charset) | |
73 (or (memq charset list) | |
74 (setq list (cons charset list))))) | |
75 (setq i (1+ i))) | |
76 list)) | 74 list)) |
77 | 75 |
78 (defalias 'find-charset-string 'charsets-in-string) | 76 (defalias 'find-charset-string 'charsets-in-string) |
79 (defalias 'find-charset-region 'charsets-in-region) | 77 (defalias 'find-charset-region 'charsets-in-region) |
80 | 78 |