From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: get-byte Date: Sun, 09 Nov 2008 22:30:16 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1226287838 4344 80.91.229.12 (10 Nov 2008 03:30:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Nov 2008 03:30:38 +0000 (UTC) Cc: eliz@gnu.org, emacs-devel@gnu.org To: Kenichi Handa Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 10 04:31:40 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KzNV4-0003jG-DV for ged-emacs-devel@m.gmane.org; Mon, 10 Nov 2008 04:31:38 +0100 Original-Received: from localhost ([127.0.0.1]:51233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzNTw-00053b-9P for ged-emacs-devel@m.gmane.org; Sun, 09 Nov 2008 22:30:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KzNTr-00053N-HU for emacs-devel@gnu.org; Sun, 09 Nov 2008 22:30:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KzNTp-00053B-6F for emacs-devel@gnu.org; Sun, 09 Nov 2008 22:30:22 -0500 Original-Received: from [199.232.76.173] (port=38332 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzNTp-000538-05 for emacs-devel@gnu.org; Sun, 09 Nov 2008 22:30:21 -0500 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:14490 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KzNTn-0000hn-KT; Sun, 09 Nov 2008 22:30:19 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArMEAEs5F0lFxLQU/2dsb2JhbACBdsYzg1iBEQ X-IronPort-AV: E=Sophos;i="4.33,572,1220241600"; d="scan'208";a="29600614" Original-Received: from 69-196-180-20.dsl.teksavvy.com (HELO ceviche.home) ([69.196.180.20]) by ironport2-out.teksavvy.com with ESMTP; 09 Nov 2008 22:30:16 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id 52AC0B418E; Sun, 9 Nov 2008 22:30:16 -0500 (EST) In-Reply-To: (Kenichi Handa's message of "Mon, 10 Nov 2008 11:20:18 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:105525 Archived-At: > 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) ..)) )). >> > 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