diff 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
line wrap: on
line diff
--- a/lisp/mule/mule-charset.el	Sun Feb 16 22:52:43 2003 +0000
+++ b/lisp/mule/mule-charset.el	Mon Feb 17 14:51:02 2003 +0000
@@ -38,6 +38,12 @@
 
 ;;;; Classifying text according to charsets
 
+;; the old version was broken in a couple of ways
+;; this is one of several versions, I tried a hash as well as the
+;; `prev-charset' cache used in the old version, but this was definitely
+;; faster than the hash version and marginally faster than the prev-charset
+;; version
+;; #### this really needs to be moved into C
 (defun charsets-in-region (start end &optional buffer)
   "Return a list of the charsets in the region between START and END.
 BUFFER defaults to the current buffer if omitted."
@@ -49,30 +55,22 @@
 	(narrow-to-region start end)
 	(goto-char (point-min))
 	(while (not (eobp))
-	  (let* (prev-charset
-		 (ch (char-after (point)))
-		 (charset (char-charset ch)))
-	    (if (not (eq prev-charset charset))
-		(progn
-		  (setq prev-charset charset)
-		  (or (memq charset list)
-		      (setq list (cons charset list))))))
+	  ;; the first test will usually succeed on testing the
+	  ;; car of the list; don't waste time let-binding.
+	  (or (memq (char-charset (char-after (point))) list)
+	      (setq list (cons (char-charset (char-after (point))) list)))
 	  (forward-char))))
     list))
 
 (defun charsets-in-string (string)
   "Return a list of the charsets in STRING."
-  (let ((i 0)
- 	(len (length string))
- 	prev-charset charset list)
-    (while (< i len)
-      (setq charset (char-charset (aref string i)))
-      (if (not (eq prev-charset charset))
- 	  (progn
- 	    (setq prev-charset charset)
- 	    (or (memq charset list)
- 		(setq list (cons charset list)))))
-      (setq i (1+ i)))
+  (let (list)
+    (mapc (lambda (ch)
+	    ;; the first test will usually succeed on testing the
+	    ;; car of the list; don't waste time let-binding.
+	    (or (memq (char-charset ch) list)
+		(setq list (cons (char-charset ch) list))))
+	  string)
     list))
 
 (defalias 'find-charset-string 'charsets-in-string)