unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Stefan Monnier" <monnier+gnu/emacs@RUM.cs.yale.edu>
Cc: "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu>,
	rms@gnu.org, emacs-devel@gnu.org
Subject: Re: enhanced select-safe-coding-system
Date: Sun, 05 May 2002 19:24:39 -0400	[thread overview]
Message-ID: <200205052324.g45NOd729789@rum.cs.yale.edu> (raw)
In-Reply-To: rzqd6wb1pzr.fsf@djlvig.dl.ac.uk

> "Stefan Monnier" <monnier+gnu/emacs@RUM.cs.yale.edu> 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.  */

  reply	other threads:[~2002-05-05 23:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <rzqk7qp2log.fsf@djlvig.dl.ac.uk>
2002-05-01  7:14 ` enhanced select-safe-coding-system Richard Stallman
2002-05-01 16:27   ` Eli Zaretskii
2002-05-01 18:51     ` Stefan Monnier
2002-05-02 22:16     ` Richard Stallman
2002-05-02 22:41     ` Dave Love
2002-05-03  7:54       ` Eli Zaretskii
2002-05-04 23:01         ` Dave Love
2002-05-02 22:39   ` Dave Love
2002-05-03 13:27     ` Stefan Monnier
2002-05-04  3:36       ` Richard Stallman
2002-05-05 23:06         ` Stefan Monnier
2002-05-04 22:56       ` Dave Love
2002-05-05 23:24         ` Stefan Monnier [this message]
2002-05-08 22:17           ` Dave Love
2002-05-14 19:41           ` Richard Stallman
2002-05-14 19:52             ` Stefan Monnier
2002-05-16  7:21               ` Richard Stallman
2002-05-04  3:36     ` Richard Stallman
2002-05-04 23:11       ` Dave Love

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200205052324.g45NOd729789@rum.cs.yale.edu \
    --to=monnier+gnu/emacs@rum.cs.yale.edu \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).