emacs-devel
[Top][All Lists]
Advanced

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

Re: get-byte


From: Kenichi Handa
Subject: Re: get-byte
Date: Mon, 10 Nov 2008 11:20:18 +0900
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/23.0.60 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

In article <address@hidden>, Stefan Monnier <address@hidden> writes:

>>> Then let's write get-byte using encode-char.  I don't care how trivial
>>> is it (I think it isn't, not unless you know very well how raw bytes
>>> are handled in Emacs buffers and strings), I think we do need such an API.
> > I've just installed get-byte.

> As already mentioned I think the important function to provide is
> `encode-char' for that functionality.  Yes, I see you provide `get-byte'
> but can encode-char be used for it now?  If so how?

Yes, we can use encode-char to implement get-byte as this:

(defun get-byte (&optional pos string)
  (let ((multibyte (if string (multibyte-string-p string)
                     enable-multibyte-characters))
        (ch (if string (aref string (or pos 0)) 
              (char-after (or pos (point))))))
    (if (< ch #x80)
        ch
      (if multibyte
          (or (encode-char ch 'eight-bit)
              (error "Not an ASCII nor an 8-bit character: %d" ch))
        ch))))

But it's 5 to 10 times slower than the C version.

> > I wrote it in C because, I think it must run very fast in
> > the situaiont when this function is called.

> Currently I don't see it being used.  Where is it going to be used?

At everywhere you want to play with binary data that is
stored in a multibyte buffer/string.  By grepping
multibyte-char-to-unibyte, I found these places;
quoted-printable-encode-region, ctext-post-read-conversion.
It seems that arc-mode should also use it unless it is
re-written to use buffer-swap-text as tar-mode.

---
Kenichi Handa
address@hidden




reply via email to

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