Commit 13002885 authored by Dmitry Antipov's avatar Dmitry Antipov
Browse files

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.
parent 99e9311c
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.
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -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.
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment