diff options
| author | Dmitry Antipov | 2012-12-20 20:09:05 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-12-20 20:09:05 +0400 |
| commit | 13002885275be0499d0131d4d1823d5e5a6a1be6 (patch) | |
| tree | 533c02f80d9a86b08aef35c2499e948ef0236f17 /src | |
| parent | 99e9311c311ec85dfb8a56d560e3d2f27abc430d (diff) | |
| download | emacs-13002885275be0499d0131d4d1823d5e5a6a1be6.tar.gz emacs-13002885275be0499d0131d4d1823d5e5a6a1be6.zip | |
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')
| -rw-r--r-- | src/ChangeLog | 17 | ||||
| -rw-r--r-- | src/editfns.c | 4 | ||||
| -rw-r--r-- | src/fileio.c | 2 | ||||
| -rw-r--r-- | src/indent.c | 3 | ||||
| -rw-r--r-- | src/insdel.c | 2 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/marker.c | 21 | ||||
| -rw-r--r-- | src/process.c | 16 | ||||
| -rw-r--r-- | src/search.c | 2 |
9 files changed, 38 insertions, 30 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7d1b78a5102..f9c629c1c56 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2012-12-20 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Avoid calls to CHAR_TO_BYTE if byte position is known. | ||
| 4 | * editfns.c (make_buffer_string_both): Use move_gap_both. | ||
| 5 | (Fbuffer_string): Use make_buffer_string_both. | ||
| 6 | * marker.c (buf_charpos_to_bytepos): Convert to eassert. | ||
| 7 | Adjust comment. | ||
| 8 | (buf_bytepos_to_charpos): Likewise. | ||
| 9 | (charpos_to_bytepos): Remove. | ||
| 10 | * fileio.c (Finsert_file_contents): Use move_gap_both. | ||
| 11 | * search.c (Freplace_match): Likewise. | ||
| 12 | * process.c (process_send_region): Likewise. Use convenient | ||
| 13 | names for byte positions. | ||
| 14 | * lisp.h (charpos_to_bytepos): Remove prototype. | ||
| 15 | * indent.c (scan_for_column): Use CHAR_TO_BYTE. | ||
| 16 | * insdel.c (move_gap): Likewise. | ||
| 17 | |||
| 1 | 2012-12-20 Paul Eggert <eggert@cs.ucla.edu> | 18 | 2012-12-20 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 19 | ||
| 3 | * xdisp.c (redisplay_internal): Remove now-unused local. | 20 | * xdisp.c (redisplay_internal): Remove now-unused local. |
diff --git a/src/editfns.c b/src/editfns.c index 911cd416e80..d7fe1c1c4c4 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2501,7 +2501,7 @@ make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte, | |||
| 2501 | Lisp_Object result, tem, tem1; | 2501 | Lisp_Object result, tem, tem1; |
| 2502 | 2502 | ||
| 2503 | if (start < GPT && GPT < end) | 2503 | if (start < GPT && GPT < end) |
| 2504 | move_gap (start); | 2504 | move_gap_both (start, start_byte); |
| 2505 | 2505 | ||
| 2506 | if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) | 2506 | if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) |
| 2507 | result = make_uninit_multibyte_string (end - start, end_byte - start_byte); | 2507 | 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 | |||
| 2599 | of the buffer. */) | 2599 | of the buffer. */) |
| 2600 | (void) | 2600 | (void) |
| 2601 | { | 2601 | { |
| 2602 | return make_buffer_string (BEGV, ZV, 1); | 2602 | return make_buffer_string_both (BEGV, BEGV_BYTE, ZV, ZV_BYTE, 1); |
| 2603 | } | 2603 | } |
| 2604 | 2604 | ||
| 2605 | DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, | 2605 | DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, |
diff --git a/src/fileio.c b/src/fileio.c index 26150a7e55b..45f3b77d721 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4131,7 +4131,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 4131 | prepare_to_modify_buffer (GPT, GPT, NULL); | 4131 | prepare_to_modify_buffer (GPT, GPT, NULL); |
| 4132 | } | 4132 | } |
| 4133 | 4133 | ||
| 4134 | move_gap (PT); | 4134 | move_gap_both (PT, PT_BYTE); |
| 4135 | if (GAP_SIZE < total) | 4135 | if (GAP_SIZE < total) |
| 4136 | make_gap (total - GAP_SIZE); | 4136 | make_gap (total - GAP_SIZE); |
| 4137 | 4137 | ||
diff --git a/src/indent.c b/src/indent.c index 3dbf372cf17..c1ddbfd236f 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -571,7 +571,8 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol) | |||
| 571 | col += width; | 571 | col += width; |
| 572 | if (endp > scan) /* Avoid infinite loops with 0-width overlays. */ | 572 | if (endp > scan) /* Avoid infinite loops with 0-width overlays. */ |
| 573 | { | 573 | { |
| 574 | scan = endp; scan_byte = charpos_to_bytepos (scan); | 574 | scan = endp; |
| 575 | scan_byte = CHAR_TO_BYTE (scan); | ||
| 575 | continue; | 576 | continue; |
| 576 | } | 577 | } |
| 577 | } | 578 | } |
diff --git a/src/insdel.c b/src/insdel.c index 74e938c4b8c..f9eff889bd4 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -90,7 +90,7 @@ check_markers (void) | |||
| 90 | void | 90 | void |
| 91 | move_gap (ptrdiff_t charpos) | 91 | move_gap (ptrdiff_t charpos) |
| 92 | { | 92 | { |
| 93 | move_gap_both (charpos, charpos_to_bytepos (charpos)); | 93 | move_gap_both (charpos, CHAR_TO_BYTE (charpos)); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | /* Move gap to byte position BYTEPOS, which is also char position CHARPOS. | 96 | /* Move gap to byte position BYTEPOS, which is also char position CHARPOS. |
diff --git a/src/lisp.h b/src/lisp.h index 9af52c09782..cfdff6cf514 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3176,7 +3176,6 @@ extern void keys_of_buffer (void); | |||
| 3176 | extern ptrdiff_t marker_position (Lisp_Object); | 3176 | extern ptrdiff_t marker_position (Lisp_Object); |
| 3177 | extern ptrdiff_t marker_byte_position (Lisp_Object); | 3177 | extern ptrdiff_t marker_byte_position (Lisp_Object); |
| 3178 | extern void clear_charpos_cache (struct buffer *); | 3178 | extern void clear_charpos_cache (struct buffer *); |
| 3179 | extern ptrdiff_t charpos_to_bytepos (ptrdiff_t); | ||
| 3180 | extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t); | 3179 | extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t); |
| 3181 | extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t); | 3180 | extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t); |
| 3182 | extern void unchain_marker (struct Lisp_Marker *marker); | 3181 | extern void unchain_marker (struct Lisp_Marker *marker); |
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) | |||
| 82 | and everywhere there is a marker. So we find the one of these places | 82 | and everywhere there is a marker. So we find the one of these places |
| 83 | that is closest to the specified position, and scan from there. */ | 83 | that is closest to the specified position, and scan from there. */ |
| 84 | 84 | ||
| 85 | /* charpos_to_bytepos returns the byte position corresponding to CHARPOS. */ | 85 | /* This macro is a subroutine of buf_charpos_to_bytepos. |
| 86 | |||
| 87 | /* This macro is a subroutine of charpos_to_bytepos. | ||
| 88 | Note that it is desirable that BYTEPOS is not evaluated | 86 | Note that it is desirable that BYTEPOS is not evaluated |
| 89 | except when we really want its value. */ | 87 | except when we really want its value. */ |
| 90 | 88 | ||
| @@ -128,11 +126,7 @@ clear_charpos_cache (struct buffer *b) | |||
| 128 | } \ | 126 | } \ |
| 129 | } | 127 | } |
| 130 | 128 | ||
| 131 | ptrdiff_t | 129 | /* Return the byte position corresponding to CHARPOS in B. */ |
| 132 | charpos_to_bytepos (ptrdiff_t charpos) | ||
| 133 | { | ||
| 134 | return buf_charpos_to_bytepos (current_buffer, charpos); | ||
| 135 | } | ||
| 136 | 130 | ||
| 137 | ptrdiff_t | 131 | ptrdiff_t |
| 138 | buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) | 132 | buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) |
| @@ -141,8 +135,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) | |||
| 141 | ptrdiff_t best_above, best_above_byte; | 135 | ptrdiff_t best_above, best_above_byte; |
| 142 | ptrdiff_t best_below, best_below_byte; | 136 | ptrdiff_t best_below, best_below_byte; |
| 143 | 137 | ||
| 144 | if (charpos < BUF_BEG (b) || charpos > BUF_Z (b)) | 138 | eassert (BUF_BEG (b) <= charpos && charpos <= BUF_Z (b)); |
| 145 | emacs_abort (); | ||
| 146 | 139 | ||
| 147 | best_above = BUF_Z (b); | 140 | best_above = BUF_Z (b); |
| 148 | best_above_byte = BUF_Z_BYTE (b); | 141 | best_above_byte = BUF_Z_BYTE (b); |
| @@ -242,9 +235,6 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) | |||
| 242 | 235 | ||
| 243 | #undef CONSIDER | 236 | #undef CONSIDER |
| 244 | 237 | ||
| 245 | /* buf_bytepos_to_charpos returns the char position corresponding to | ||
| 246 | BYTEPOS. */ | ||
| 247 | |||
| 248 | /* This macro is a subroutine of buf_bytepos_to_charpos. | 238 | /* This macro is a subroutine of buf_bytepos_to_charpos. |
| 249 | It is used when BYTEPOS is actually the byte position. */ | 239 | It is used when BYTEPOS is actually the byte position. */ |
| 250 | 240 | ||
| @@ -288,6 +278,8 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) | |||
| 288 | } \ | 278 | } \ |
| 289 | } | 279 | } |
| 290 | 280 | ||
| 281 | /* Return the character position corresponding to BYTEPOS in B. */ | ||
| 282 | |||
| 291 | ptrdiff_t | 283 | ptrdiff_t |
| 292 | buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) | 284 | buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) |
| 293 | { | 285 | { |
| @@ -295,8 +287,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) | |||
| 295 | ptrdiff_t best_above, best_above_byte; | 287 | ptrdiff_t best_above, best_above_byte; |
| 296 | ptrdiff_t best_below, best_below_byte; | 288 | ptrdiff_t best_below, best_below_byte; |
| 297 | 289 | ||
| 298 | if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b)) | 290 | eassert (BUF_BEG_BYTE (b) <= bytepos && bytepos <= BUF_Z_BYTE (b)); |
| 299 | emacs_abort (); | ||
| 300 | 291 | ||
| 301 | best_above = BUF_Z (b); | 292 | best_above = BUF_Z (b); |
| 302 | best_above_byte = BUF_Z_BYTE (b); | 293 | best_above_byte = BUF_Z_BYTE (b); |
diff --git a/src/process.c b/src/process.c index 92d5e692d0b..7ab651a2376 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -5556,19 +5556,19 @@ it is sent in several bunches. This may happen even for shorter regions. | |||
| 5556 | Output from processes can arrive in between bunches. */) | 5556 | Output from processes can arrive in between bunches. */) |
| 5557 | (Lisp_Object process, Lisp_Object start, Lisp_Object end) | 5557 | (Lisp_Object process, Lisp_Object start, Lisp_Object end) |
| 5558 | { | 5558 | { |
| 5559 | Lisp_Object proc; | 5559 | Lisp_Object proc = get_process (process); |
| 5560 | ptrdiff_t start1, end1; | 5560 | ptrdiff_t start_byte, end_byte; |
| 5561 | 5561 | ||
| 5562 | proc = get_process (process); | ||
| 5563 | validate_region (&start, &end); | 5562 | validate_region (&start, &end); |
| 5564 | 5563 | ||
| 5564 | start_byte = CHAR_TO_BYTE (XINT (start)); | ||
| 5565 | end_byte = CHAR_TO_BYTE (XINT (end)); | ||
| 5566 | |||
| 5565 | if (XINT (start) < GPT && XINT (end) > GPT) | 5567 | if (XINT (start) < GPT && XINT (end) > GPT) |
| 5566 | move_gap (XINT (start)); | 5568 | move_gap_both (XINT (start), start_byte); |
| 5567 | 5569 | ||
| 5568 | start1 = CHAR_TO_BYTE (XINT (start)); | 5570 | send_process (proc, (char *) BYTE_POS_ADDR (start_byte), |
| 5569 | end1 = CHAR_TO_BYTE (XINT (end)); | 5571 | end_byte - start_byte, Fcurrent_buffer ()); |
| 5570 | send_process (proc, (char *) BYTE_POS_ADDR (start1), end1 - start1, | ||
| 5571 | Fcurrent_buffer ()); | ||
| 5572 | 5572 | ||
| 5573 | return Qnil; | 5573 | return Qnil; |
| 5574 | } | 5574 | } |
diff --git a/src/search.c b/src/search.c index 7f26601cc69..394012b2761 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2599,7 +2599,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2599 | ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]); | 2599 | ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]); |
| 2600 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; | 2600 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; |
| 2601 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) | 2601 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) |
| 2602 | move_gap (search_regs.start[idx]); | 2602 | move_gap_both (search_regs.start[idx], begbyte); |
| 2603 | add_stuff = BYTE_POS_ADDR (begbyte); | 2603 | add_stuff = BYTE_POS_ADDR (begbyte); |
| 2604 | } | 2604 | } |
| 2605 | 2605 | ||