[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: get-byte
From: |
Stefan Monnier |
Subject: |
Re: get-byte |
Date: |
Sun, 09 Nov 2008 22:30:16 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
> 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'm not opposed to `get-byte' being implemented in C. I just think it
should be implementable as
(defun get-byte (&optional pos string)
(let ((ch (if string (aref string (or pos 0))
(char-after pos))))
(or (encode-char ch 'binary)
(error "Not an ASCII nor an 8-bit character: %d" ch))))
Given that, in most cases where you'd use get-byte you could replace it
with either (encode-char (char-after POS) 'binary)
or (encode-char (aref STRING POS) 'binary). It may still be
significantly slower than a direct C implementation of get-byte, but it
is the right functionality to provide (i.e. get-byte is only there for
optimization purposes) and in some cases get-byte is not an option
(e.g. in cases such as (mapcar (lambda (c) (... (encode-char c 'binary)
..)) <string>)).
>> > 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.
I see.
> It seems that arc-mode should also use it unless it is
> re-written to use buffer-swap-text as tar-mode.
This one needs to be converted to use buffer-swap-text indeed.
Stefan