[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: enhanced select-safe-coding-system
From: |
Stefan Monnier |
Subject: |
Re: enhanced select-safe-coding-system |
Date: |
Sun, 05 May 2002 19:24:39 -0400 |
> "Stefan Monnier" <monnier+gnu/address@hidden> 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. */
- Re: enhanced select-safe-coding-system, (continued)
Re: enhanced select-safe-coding-system, Dave Love, 2002/05/02
- Re: enhanced select-safe-coding-system, Stefan Monnier, 2002/05/03
- Re: enhanced select-safe-coding-system, Dave Love, 2002/05/04
- Re: enhanced select-safe-coding-system,
Stefan Monnier <=
- Re: enhanced select-safe-coding-system, Dave Love, 2002/05/08
- Re: enhanced select-safe-coding-system, Richard Stallman, 2002/05/14
- Re: enhanced select-safe-coding-system, Stefan Monnier, 2002/05/14
- Re: enhanced select-safe-coding-system, Richard Stallman, 2002/05/16
Re: enhanced select-safe-coding-system, Richard Stallman, 2002/05/03