summaryrefslogtreecommitdiff
path: root/src/marker.c
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2012-12-20 20:09:05 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2012-12-20 20:09:05 +0400
commit13002885275be0499d0131d4d1823d5e5a6a1be6 (patch)
tree533c02f80d9a86b08aef35c2499e948ef0236f17 /src/marker.c
parent99e9311c311ec85dfb8a56d560e3d2f27abc430d (diff)
downloademacs-13002885275be0499d0131d4d1823d5e5a6a1be6.tar.gz
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.
Diffstat (limited to 'src/marker.c')
-rw-r--r--src/marker.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/marker.c b/src/marker.c
index 69be4faec3a..0df03e01734 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -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);