From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: enhanced select-safe-coding-system Date: Sun, 05 May 2002 19:24:39 -0400 Sender: emacs-devel-admin@gnu.org Message-ID: <200205052324.g45NOd729789@rum.cs.yale.edu> References: <200205010714.g417Eq607434@aztec.santafe.edu> <200205031327.g43DR1014311@rum.cs.yale.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1020641247 17672 127.0.0.1 (5 May 2002 23:27:27 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 5 May 2002 23:27:27 +0000 (UTC) Cc: "Stefan Monnier" , rms@gnu.org, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 174VPb-0004av-00 for ; Mon, 06 May 2002 01:27:27 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 174VWU-00057I-00 for ; Mon, 06 May 2002 01:34:34 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 174VPE-0000Nr-00; Sun, 05 May 2002 19:27:04 -0400 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 174VMw-0000Jr-00; Sun, 05 May 2002 19:24:42 -0400 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.11.6/8.11.6) id g45NOd729789; Sun, 5 May 2002 19:24:39 -0400 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Dave Love Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:3617 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:3617 > "Stefan Monnier" writes: > > > I have recently posted a fairly simple patch that does that by slightly > > modifying the C code, so it's fast. > > How is that? I think the Lisp is actually fast enough in that > application on a P100. I included the warning in case anyone used it > without checking. You might be right that the elisp code is fast enough, but my patch (attached) makes fewer changes and avoids re-implementing the same functionality in elisp. Stefan Index: coding.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/coding.c,v retrieving revision 1.241 diff -u -r1.241 coding.c --- coding.c 13 Apr 2002 17:49:00 -0000 1.241 +++ coding.c 5 May 2002 23:23:51 -0000 @@ -6366,8 +6361,6 @@ continue; if (SINGLE_BYTE_CHAR_P (c)) *single_byte_char_found = 1; - if (NILP (safe_codings)) - continue; /* Check the safe coding systems for C. */ val = char_table_ref_and_index (work_table, c, &idx); if (EQ (val, Qt)) @@ -6382,6 +6375,8 @@ if (!EQ (safe_codings, Qt) && !NILP (val)) val = intersection (safe_codings, val); safe_codings = val; + if (NILP (safe_codings)) + return make_number (pend - p); } return safe_codings; } @@ -6393,20 +6388,24 @@ DEFUN ("find-coding-systems-region-internal", Ffind_coding_systems_region_internal, - Sfind_coding_systems_region_internal, 2, 2, 0, + Sfind_coding_systems_region_internal, 2, 3, 0, doc: /* Internal use only. */) - (start, end) - Lisp_Object start, end; + (start, end, safe_codings) + Lisp_Object start, end, safe_codings; { - Lisp_Object work_table, safe_codings; + Lisp_Object work_table; int non_ascii_p = 0; int single_byte_char_found = 0; unsigned char *p1, *p1end, *p2, *p2end, *p; + int from, to, stop; + + if (NILP (safe_codings)) + safe_codings = Qt; if (STRINGP (start)) { if (!STRING_MULTIBYTE (start)) - return Qt; + return safe_codings; p1 = XSTRING (start)->data, p1end = p1 + STRING_BYTES (XSTRING (start)); p2 = p2end = p1end; if (XSTRING (start)->size != STRING_BYTES (XSTRING (start))) @@ -6414,14 +6413,12 @@ } else { - int from, to, stop; - CHECK_NUMBER_COERCE_MARKER (start); CHECK_NUMBER_COERCE_MARKER (end); if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) args_out_of_range (start, end); if (NILP (current_buffer->enable_multibyte_characters)) - return Qt; + return safe_codings; from = CHAR_TO_BYTE (XINT (start)); to = CHAR_TO_BYTE (XINT (end)); stop = from < GPT_BYTE && GPT_BYTE < to ? GPT_BYTE : to; @@ -6444,17 +6441,27 @@ { for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++); if (p == p2end) - return Qt; + return safe_codings; } } /* The text contains non-ASCII characters. */ work_table = Fcopy_sequence (Vchar_coding_system_table); - safe_codings = find_safe_codings (p1, p1end, Qt, work_table, + safe_codings = find_safe_codings (p1, p1end, safe_codings, work_table, &single_byte_char_found); + if (INTEGERP (safe_codings)) + { + int byte = p1end - p1 - XINT (safe_codings); + return (STRINGP (start) + ? string_byte_to_char (start, byte) + : bytepos_to_charpos (byte + from)) - 1; + } if (p2 < p2end) safe_codings = find_safe_codings (p2, p2end, safe_codings, work_table, &single_byte_char_found); + if (INTEGERP (safe_codings)) + return bytepos_to_charpos (p2end - p2 - XINT (safe_codings) + stop) - 1; + if (EQ (safe_codings, Qt)) ; /* Nothing to be done. */