]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid calls to CHAR_TO_BYTE if byte position is known.
authorDmitry Antipov <dmantipov@yandex.ru>
Thu, 20 Dec 2012 16:09:05 +0000 (20:09 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Thu, 20 Dec 2012 16:09:05 +0000 (20:09 +0400)
* editfns.c (make_buffer_string_both): Use move_gap_both.
(Fbuffer_string): Use make_buffer_string_both.
* marker.c (buf_charpos_to_bytepos): Convert to eassert.
Adjust comment.
(buf_bytepos_to_charpos): Likewise.
(charpos_to_bytepos): Remove.
* fileio.c (Finsert_file_contents): Use move_gap_both.
* search.c (Freplace_match): Likewise.
* process.c (process_send_region): Likewise. Use convenient
names for byte positions.
* lisp.h (charpos_to_bytepos): Remove prototype.
* indent.c (scan_for_column): Use CHAR_TO_BYTE.
* insdel.c (move_gap): Likewise.

src/ChangeLog
src/editfns.c
src/fileio.c
src/indent.c
src/insdel.c
src/lisp.h
src/marker.c
src/process.c
src/search.c

index 7d1b78a51027c9c339d5ede03733b5d8e36ed4b0..f9c629c1c5630badbcac693997801e63ab75b4df 100644 (file)
@@ -1,3 +1,20 @@
+2012-12-20  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Avoid calls to CHAR_TO_BYTE if byte position is known.
+       * editfns.c (make_buffer_string_both): Use move_gap_both.
+       (Fbuffer_string): Use make_buffer_string_both.
+       * marker.c (buf_charpos_to_bytepos): Convert to eassert.
+       Adjust comment.
+       (buf_bytepos_to_charpos): Likewise.
+       (charpos_to_bytepos): Remove.
+       * fileio.c (Finsert_file_contents): Use move_gap_both.
+       * search.c (Freplace_match): Likewise.
+       * process.c (process_send_region): Likewise. Use convenient
+       names for byte positions.
+       * lisp.h (charpos_to_bytepos): Remove prototype.
+       * indent.c (scan_for_column): Use CHAR_TO_BYTE.
+       * insdel.c (move_gap): Likewise.
+
 2012-12-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        * xdisp.c (redisplay_internal): Remove now-unused local.
index 911cd416e80a79399f2fc585735efe06dca9fed0..d7fe1c1c4c4299cc82a4cc3cc3b1ac0b94b5bfb8 100644 (file)
@@ -2501,7 +2501,7 @@ make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
   Lisp_Object result, tem, tem1;
 
   if (start < GPT && GPT < end)
-    move_gap (start);
+    move_gap_both (start, start_byte);
 
   if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
     result = make_uninit_multibyte_string (end - start, end_byte - start_byte);
@@ -2599,7 +2599,7 @@ If narrowing is in effect, this function returns only the visible part
 of the buffer.  */)
   (void)
 {
-  return make_buffer_string (BEGV, ZV, 1);
+  return make_buffer_string_both (BEGV, BEGV_BYTE, ZV, ZV_BYTE, 1);
 }
 
 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
index 26150a7e55b1237d0d687769f05c6a418a4e67c7..45f3b77d721f87b83f50ac4b27eece18e8058bc6 100644 (file)
@@ -4131,7 +4131,7 @@ variable `last-coding-system-used' to the coding system actually used.  */)
       prepare_to_modify_buffer (GPT, GPT, NULL);
     }
 
-  move_gap (PT);
+  move_gap_both (PT, PT_BYTE);
   if (GAP_SIZE < total)
     make_gap (total - GAP_SIZE);
 
index 3dbf372cf17c99b4227cee774470c7b8534fa768..c1ddbfd236f6e8c1268cd46781d54ebe4dcdbbc8 100644 (file)
@@ -571,7 +571,8 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol)
            col += width;
            if (endp > scan) /* Avoid infinite loops with 0-width overlays.  */
              {
-               scan = endp; scan_byte = charpos_to_bytepos (scan);
+               scan = endp;
+               scan_byte = CHAR_TO_BYTE (scan);
                continue;
              }
          }
index 74e938c4b8c4e5a83ae0f83f9f6e20ec79a5bf73..f9eff889bd4658cbb63a090cd2c4ccc0811d59af 100644 (file)
@@ -90,7 +90,7 @@ check_markers (void)
 void
 move_gap (ptrdiff_t charpos)
 {
-  move_gap_both (charpos, charpos_to_bytepos (charpos));
+  move_gap_both (charpos, CHAR_TO_BYTE (charpos));
 }
 
 /* Move gap to byte position BYTEPOS, which is also char position CHARPOS.
index 9af52c097829122c8094e260ed6823db8cfc2488..cfdff6cf51409aa1161055adfba2b8a7a603ec45 100644 (file)
@@ -3176,7 +3176,6 @@ extern void keys_of_buffer (void);
 extern ptrdiff_t marker_position (Lisp_Object);
 extern ptrdiff_t marker_byte_position (Lisp_Object);
 extern void clear_charpos_cache (struct buffer *);
-extern ptrdiff_t charpos_to_bytepos (ptrdiff_t);
 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
 extern void unchain_marker (struct Lisp_Marker *marker);
index 69be4faec3a5d832ad1ceaf41a8b4b7d2153928a..0df03e017340411a68db768f1dbe9be977e80e4d 100644 (file)
@@ -82,9 +82,7 @@ clear_charpos_cache (struct buffer *b)
    and everywhere there is a marker.  So we find the one of these places
    that is closest to the specified position, and scan from there.  */
 
-/* charpos_to_bytepos returns the byte position corresponding to CHARPOS.  */
-
-/* This macro is a subroutine of charpos_to_bytepos.
+/* This macro is a subroutine of buf_charpos_to_bytepos.
    Note that it is desirable that BYTEPOS is not evaluated
    except when we really want its value.  */
 
@@ -128,11 +126,7 @@ clear_charpos_cache (struct buffer *b)
     }                                                                  \
 }
 
-ptrdiff_t
-charpos_to_bytepos (ptrdiff_t charpos)
-{
-  return buf_charpos_to_bytepos (current_buffer, charpos);
-}
+/* Return the byte position corresponding to CHARPOS in B.  */
 
 ptrdiff_t
 buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
@@ -141,8 +135,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
   ptrdiff_t best_above, best_above_byte;
   ptrdiff_t best_below, best_below_byte;
 
-  if (charpos < BUF_BEG (b) || charpos > BUF_Z (b))
-    emacs_abort ();
+  eassert (BUF_BEG (b) <= charpos && charpos <= BUF_Z (b));
 
   best_above = BUF_Z (b);
   best_above_byte = BUF_Z_BYTE (b);
@@ -242,9 +235,6 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
 
 #undef CONSIDER
 
-/* buf_bytepos_to_charpos returns the char position corresponding to
-   BYTEPOS.  */
-
 /* This macro is a subroutine of buf_bytepos_to_charpos.
    It is used when BYTEPOS is actually the byte position.  */
 
@@ -288,6 +278,8 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
     }                                                                  \
 }
 
+/* Return the character position corresponding to BYTEPOS in B.  */
+
 ptrdiff_t
 buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
 {
@@ -295,8 +287,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
   ptrdiff_t best_above, best_above_byte;
   ptrdiff_t best_below, best_below_byte;
 
-  if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b))
-    emacs_abort ();
+  eassert (BUF_BEG_BYTE (b) <= bytepos && bytepos <= BUF_Z_BYTE (b));
 
   best_above = BUF_Z (b);
   best_above_byte = BUF_Z_BYTE (b);
index 92d5e692d0b42d56f67cd2c884040340f922ef62..7ab651a237692e625fd23d22a362962a5a0c8589 100644 (file)
@@ -5556,19 +5556,19 @@ it is sent in several bunches.  This may happen even for shorter regions.
 Output from processes can arrive in between bunches.  */)
   (Lisp_Object process, Lisp_Object start, Lisp_Object end)
 {
-  Lisp_Object proc;
-  ptrdiff_t start1, end1;
+  Lisp_Object proc = get_process (process);
+  ptrdiff_t start_byte, end_byte;
 
-  proc = get_process (process);
   validate_region (&start, &end);
 
+  start_byte = CHAR_TO_BYTE (XINT (start));
+  end_byte = CHAR_TO_BYTE (XINT (end));
+
   if (XINT (start) < GPT && XINT (end) > GPT)
-    move_gap (XINT (start));
+    move_gap_both (XINT (start), start_byte);
 
-  start1 = CHAR_TO_BYTE (XINT (start));
-  end1 = CHAR_TO_BYTE (XINT (end));
-  send_process (proc, (char *) BYTE_POS_ADDR (start1), end1 - start1,
-               Fcurrent_buffer ());
+  send_process (proc, (char *) BYTE_POS_ADDR (start_byte), 
+               end_byte - start_byte, Fcurrent_buffer ());
 
   return Qnil;
 }
index 7f26601cc6941849f379df45b23e9d35925fdc14..394012b276172411f94d7fed050ba5d2745644a0 100644 (file)
@@ -2599,7 +2599,7 @@ since only regular expressions have distinguished subexpressions.  */)
              ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
              add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
              if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
-               move_gap (search_regs.start[idx]);
+               move_gap_both (search_regs.start[idx], begbyte);
              add_stuff = BYTE_POS_ADDR (begbyte);
            }