]> git.eshelyaron.com Git - emacs.git/commitdiff
On file insertion, skip decoding if all bytes are ASCII.
authorKenichi Handa <handa@gnu.org>
Sun, 10 Mar 2013 14:36:35 +0000 (23:36 +0900)
committerKenichi Handa <handa@gnu.org>
Sun, 10 Mar 2013 14:36:35 +0000 (23:36 +0900)
src/ChangeLog
src/coding.c
src/insdel.c
src/lisp.h

index ae25a3c5d00d3efd661aa3477d8af3ab06526891..2c77950c2624a136a8ddfe08533bf6586f5a75b8 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-10  handa  <handa@gnu.org>
+
+       * lisp.h (adjust_after_replace): Extern it.
+
+       * coding.c (detect_coding): Cound the heading ASCII bytes in the
+       case of detection for coding_category_utf_8_auto.
+       (decode_coding_gap) [not CODING_DISABLE_ASCII_OPTIMIZATION]: Skip
+       decoding if all bytes are ASCII.
+
+       * insdel.c (adjust_after_replace): Make it public.  New arg
+       text_at_gap_tail.
+       (adjust_after_insert): Call adjust_after_replace with the new arg
+       value 0.
+
 2013-03-09  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * keyboard.h (EVENT_START, EVENT_END, POSN_WINDOW, POSN_POSN)
index 32da72ab6269a7d18171dc726be40a0e896e334b..f33b5e7c7d5ddb7f16134a97510ef2a66e460fc7 100644 (file)
@@ -6349,7 +6349,12 @@ detect_coding (struct coding_system *coding)
       coding_systems
        = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom);
       detect_info.found = detect_info.rejected = 0;
-      coding->head_ascii = 0;
+      for (src = coding->source; src < src_end; src++)
+       {
+         if (*src & 0x80)
+           break;
+       }
+      coding->head_ascii = src - coding->source;
       if (CONSP (coding_systems)
          && detect_coding_utf_8 (coding, &detect_info))
        {
@@ -7487,8 +7492,6 @@ decode_coding_gap (struct coding_system *coding,
   ptrdiff_t count = SPECPDL_INDEX ();
   Lisp_Object attrs;
 
-  code_conversion_save (0, 0);
-
   coding->src_object = Fcurrent_buffer ();
   coding->src_chars = chars;
   coding->src_bytes = bytes;
@@ -7502,13 +7505,45 @@ decode_coding_gap (struct coding_system *coding,
 
   if (CODING_REQUIRE_DETECTION (coding))
     detect_coding (coding);
+  attrs = CODING_ID_ATTRS (coding->id);
+#ifndef CODING_DISABLE_ASCII_OPTIMIZATION
+  if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))
+      && NILP (CODING_ATTR_POST_READ (attrs))
+      && NILP (get_translation_table (attrs, 0, NULL)))
+    {
+      /* We can skip the conversion if all source bytes are ASCII.  */
+      if (coding->head_ascii < 0)
+       {
+         /* We have not yet counted the number of ASCII bytes at the
+            head of the source.  Do it now.  */
+         const unsigned char *src, *src_end;
+
+         coding_set_source (coding);
+         src_end = coding->source + coding->src_bytes;
+         for (src = coding->source; src < src_end; src++)
+           {
+             if (*src & 0x80)
+               break;
+           }
+         coding->head_ascii = src - coding->source;
+       }
+      if (coding->src_bytes == coding->head_ascii)
+       {
+         /* No need of conversion.  Use the data in the gap as is.  */
+         coding->produced_char = chars;
+         coding->produced = bytes;
+         adjust_after_replace (PT, PT_BYTE, Qnil, chars, bytes, 1);
+         return;
+       }
+    }
+#endif /* not CODING_DISABLE_ASCII_OPTIMIZATION */
+  code_conversion_save (0, 0);
 
   coding->mode |= CODING_MODE_LAST_BLOCK;
   current_buffer->text->inhibit_shrinking = 1;
   decode_coding (coding);
   current_buffer->text->inhibit_shrinking = 0;
 
-  attrs = CODING_ID_ATTRS (coding->id);
   if (! NILP (CODING_ATTR_POST_READ (attrs)))
     {
       ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
index fc5a4576dc220842c67048de90837b2adc545a96..992cebb04b0084257a82027e76e1a22c5f92f8e9 100644 (file)
@@ -1162,14 +1162,16 @@ insert_from_buffer_1 (struct buffer *buf,
 \f
 /* Record undo information and adjust markers and position keepers for
    a replacement of a text PREV_TEXT at FROM to a new text of LEN
-   chars (LEN_BYTE bytes) which resides in the gap just after
-   GPT_ADDR.
+   chars (LEN_BYTE bytes).  If TEXT_AT_GAP_TAIL is zero, the new text
+   resides in the gap just after GPT_BYTE.  Otherwise, the text
+   resides at the gap tail; i.e. at (GAP_END_ADDR - LEN_BNYTE).
 
    PREV_TEXT nil means the new text was just inserted.  */
 
-static void
+void
 adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
-                     Lisp_Object prev_text, ptrdiff_t len, ptrdiff_t len_byte)
+                     Lisp_Object prev_text, ptrdiff_t len, ptrdiff_t len_byte,
+                     int text_at_gap_tail)
 {
   ptrdiff_t nchars_del = 0, nbytes_del = 0;
 
@@ -1189,8 +1191,11 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
   GAP_SIZE -= len_byte;
   ZV += len; Z+= len;
   ZV_BYTE += len_byte; Z_BYTE += len_byte;
-  GPT += len; GPT_BYTE += len_byte;
-  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
+  if (! text_at_gap_tail)
+    {
+      GPT += len; GPT_BYTE += len_byte;
+      if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
+    }
 
   if (nchars_del > 0)
     adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del,
@@ -1245,7 +1250,7 @@ adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
   GPT -= len; GPT_BYTE -= len_byte;
   ZV -= len; ZV_BYTE -= len_byte;
   Z -= len; Z_BYTE -= len_byte;
-  adjust_after_replace (from, from_byte, Qnil, newlen, len_byte);
+  adjust_after_replace (from, from_byte, Qnil, newlen, len_byte, 0);
 }
 \f
 /* Replace the text from character positions FROM to TO with NEW,
index e4993866b1fb2516dfd99e716cdcb7c6959c7893..171292f942e98ddae1f18ad834e7fead9f9e345d 100644 (file)
@@ -2900,6 +2900,10 @@ extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
 extern void modify_region_1 (ptrdiff_t, ptrdiff_t, bool);
 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
+extern void adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
+                                 Lisp_Object prev_text,
+                                 ptrdiff_t len, ptrdiff_t len_byte,
+                                 int text_at_gap_tail);
 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
                                 ptrdiff_t, ptrdiff_t);
 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,