aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa2013-03-10 23:36:35 +0900
committerKenichi Handa2013-03-10 23:36:35 +0900
commitc230dd7d89730f565df77046d0666d2082e386ee (patch)
tree9f63b2d8ba43f9ab3d244e252aaf9f26fea12daa /src/coding.c
parent27a98a62d1c46b057428cc3ed964743b69628299 (diff)
downloademacs-c230dd7d89730f565df77046d0666d2082e386ee.tar.gz
emacs-c230dd7d89730f565df77046d0666d2082e386ee.zip
On file insertion, skip decoding if all bytes are ASCII.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/coding.c b/src/coding.c
index 32da72ab626..f33b5e7c7d5 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6349,7 +6349,12 @@ detect_coding (struct coding_system *coding)
6349 coding_systems 6349 coding_systems
6350 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); 6350 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom);
6351 detect_info.found = detect_info.rejected = 0; 6351 detect_info.found = detect_info.rejected = 0;
6352 coding->head_ascii = 0; 6352 for (src = coding->source; src < src_end; src++)
6353 {
6354 if (*src & 0x80)
6355 break;
6356 }
6357 coding->head_ascii = src - coding->source;
6353 if (CONSP (coding_systems) 6358 if (CONSP (coding_systems)
6354 && detect_coding_utf_8 (coding, &detect_info)) 6359 && detect_coding_utf_8 (coding, &detect_info))
6355 { 6360 {
@@ -7487,8 +7492,6 @@ decode_coding_gap (struct coding_system *coding,
7487 ptrdiff_t count = SPECPDL_INDEX (); 7492 ptrdiff_t count = SPECPDL_INDEX ();
7488 Lisp_Object attrs; 7493 Lisp_Object attrs;
7489 7494
7490 code_conversion_save (0, 0);
7491
7492 coding->src_object = Fcurrent_buffer (); 7495 coding->src_object = Fcurrent_buffer ();
7493 coding->src_chars = chars; 7496 coding->src_chars = chars;
7494 coding->src_bytes = bytes; 7497 coding->src_bytes = bytes;
@@ -7502,13 +7505,45 @@ decode_coding_gap (struct coding_system *coding,
7502 7505
7503 if (CODING_REQUIRE_DETECTION (coding)) 7506 if (CODING_REQUIRE_DETECTION (coding))
7504 detect_coding (coding); 7507 detect_coding (coding);
7508 attrs = CODING_ID_ATTRS (coding->id);
7509#ifndef CODING_DISABLE_ASCII_OPTIMIZATION
7510 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))
7511 && NILP (CODING_ATTR_POST_READ (attrs))
7512 && NILP (get_translation_table (attrs, 0, NULL)))
7513 {
7514 /* We can skip the conversion if all source bytes are ASCII. */
7515 if (coding->head_ascii < 0)
7516 {
7517 /* We have not yet counted the number of ASCII bytes at the
7518 head of the source. Do it now. */
7519 const unsigned char *src, *src_end;
7520
7521 coding_set_source (coding);
7522 src_end = coding->source + coding->src_bytes;
7523 for (src = coding->source; src < src_end; src++)
7524 {
7525 if (*src & 0x80)
7526 break;
7527 }
7528 coding->head_ascii = src - coding->source;
7529 }
7530 if (coding->src_bytes == coding->head_ascii)
7531 {
7532 /* No need of conversion. Use the data in the gap as is. */
7533 coding->produced_char = chars;
7534 coding->produced = bytes;
7535 adjust_after_replace (PT, PT_BYTE, Qnil, chars, bytes, 1);
7536 return;
7537 }
7538 }
7539#endif /* not CODING_DISABLE_ASCII_OPTIMIZATION */
7540 code_conversion_save (0, 0);
7505 7541
7506 coding->mode |= CODING_MODE_LAST_BLOCK; 7542 coding->mode |= CODING_MODE_LAST_BLOCK;
7507 current_buffer->text->inhibit_shrinking = 1; 7543 current_buffer->text->inhibit_shrinking = 1;
7508 decode_coding (coding); 7544 decode_coding (coding);
7509 current_buffer->text->inhibit_shrinking = 0; 7545 current_buffer->text->inhibit_shrinking = 0;
7510 7546
7511 attrs = CODING_ID_ATTRS (coding->id);
7512 if (! NILP (CODING_ATTR_POST_READ (attrs))) 7547 if (! NILP (CODING_ATTR_POST_READ (attrs)))
7513 { 7548 {
7514 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE; 7549 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;