aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov2013-01-11 17:25:10 +0400
committerDmitry Antipov2013-01-11 17:25:10 +0400
commit6020559a093bf243be6cd6a866933b4368ea67cc (patch)
treeb722d61837c6f76447a76f58ac975f4d327ce1e4
parent30818a239e7b1222ec776603aa29786638efbb47 (diff)
downloademacs-6020559a093bf243be6cd6a866933b4368ea67cc.tar.gz
emacs-6020559a093bf243be6cd6a866933b4368ea67cc.zip
Avoid unnecessary byte position calculation for the gap movement.
Since all users of move_gap do CHAR_TO_BYTE for other purposes anyway, all of them should use move_gap_both instead. * lisp.h (move_gap): Remove prototype. * insdel.c (move_gap): Remove. (move_gap_both): Add eassert. * editfns.c (Ftranspose_regions): Tweak to use move_gap_both. * xml.c (parse_region): Likewise.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/editfns.c12
-rw-r--r--src/insdel.c11
-rw-r--r--src/lisp.h1
-rw-r--r--src/xml.c17
5 files changed, 28 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f0d875b2027..13a1f1a3858 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12013-01-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Avoid unnecessary byte position calculation for the gap movement.
4 Since all users of move_gap do CHAR_TO_BYTE for other purposes
5 anyway, all of them should use move_gap_both instead.
6 * lisp.h (move_gap): Remove prototype.
7 * insdel.c (move_gap): Remove.
8 (move_gap_both): Add eassert.
9 * editfns.c (Ftranspose_regions): Tweak to use move_gap_both.
10 * xml.c (parse_region): Likewise.
11
12013-01-11 Paul Eggert <eggert@cs.ucla.edu> 122013-01-11 Paul Eggert <eggert@cs.ucla.edu>
2 13
3 emacsclient -t should not suspend Emacs server (Bug#13387) 14 emacsclient -t should not suspend Emacs server (Bug#13387)
diff --git a/src/editfns.c b/src/editfns.c
index 26dfdac3ba8..64269bab8df 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4522,7 +4522,7 @@ Transposing beyond buffer boundaries is an error. */)
4522 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) 4522 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers)
4523{ 4523{
4524 register ptrdiff_t start1, end1, start2, end2; 4524 register ptrdiff_t start1, end1, start2, end2;
4525 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte; 4525 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte, end2_byte;
4526 ptrdiff_t gap, len1, len_mid, len2; 4526 ptrdiff_t gap, len1, len_mid, len2;
4527 unsigned char *start1_addr, *start2_addr, *temp; 4527 unsigned char *start1_addr, *start2_addr, *temp;
4528 4528
@@ -4583,20 +4583,22 @@ Transposing beyond buffer boundaries is an error. */)
4583 the gap the minimum distance to get it out of the way, and then 4583 the gap the minimum distance to get it out of the way, and then
4584 deal with an unbroken array. */ 4584 deal with an unbroken array. */
4585 4585
4586 start1_byte = CHAR_TO_BYTE (start1);
4587 end2_byte = CHAR_TO_BYTE (end2);
4588
4586 /* Make sure the gap won't interfere, by moving it out of the text 4589 /* Make sure the gap won't interfere, by moving it out of the text
4587 we will operate on. */ 4590 we will operate on. */
4588 if (start1 < gap && gap < end2) 4591 if (start1 < gap && gap < end2)
4589 { 4592 {
4590 if (gap - start1 < end2 - gap) 4593 if (gap - start1 < end2 - gap)
4591 move_gap (start1); 4594 move_gap_both (start1, start1_byte);
4592 else 4595 else
4593 move_gap (end2); 4596 move_gap_both (end2, end2_byte);
4594 } 4597 }
4595 4598
4596 start1_byte = CHAR_TO_BYTE (start1);
4597 start2_byte = CHAR_TO_BYTE (start2); 4599 start2_byte = CHAR_TO_BYTE (start2);
4598 len1_byte = CHAR_TO_BYTE (end1) - start1_byte; 4600 len1_byte = CHAR_TO_BYTE (end1) - start1_byte;
4599 len2_byte = CHAR_TO_BYTE (end2) - start2_byte; 4601 len2_byte = end2_byte - start2_byte;
4600 4602
4601#ifdef BYTE_COMBINING_DEBUG 4603#ifdef BYTE_COMBINING_DEBUG
4602 if (end1 == start2) 4604 if (end1 == start2)
diff --git a/src/insdel.c b/src/insdel.c
index 905249d6714..c2a3cd42821 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -84,21 +84,14 @@ check_markers (void)
84 84
85#endif /* MARKER_DEBUG */ 85#endif /* MARKER_DEBUG */
86 86
87/* Move gap to position CHARPOS.
88 Note that this can quit! */
89
90void
91move_gap (ptrdiff_t charpos)
92{
93 move_gap_both (charpos, CHAR_TO_BYTE (charpos));
94}
95
96/* Move gap to byte position BYTEPOS, which is also char position CHARPOS. 87/* Move gap to byte position BYTEPOS, which is also char position CHARPOS.
97 Note that this can quit! */ 88 Note that this can quit! */
98 89
99void 90void
100move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos) 91move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos)
101{ 92{
93 eassert (charpos == BYTE_TO_CHAR (bytepos)
94 && bytepos == CHAR_TO_BYTE (charpos));
102 if (bytepos < GPT_BYTE) 95 if (bytepos < GPT_BYTE)
103 gap_left (charpos, bytepos, 0); 96 gap_left (charpos, bytepos, 0);
104 else if (bytepos > GPT_BYTE) 97 else if (bytepos > GPT_BYTE)
diff --git a/src/lisp.h b/src/lisp.h
index 3200127881b..22e0a188e4b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2775,7 +2775,6 @@ extern void syms_of_image (void);
2775 2775
2776/* Defined in insdel.c. */ 2776/* Defined in insdel.c. */
2777extern Lisp_Object Qinhibit_modification_hooks; 2777extern Lisp_Object Qinhibit_modification_hooks;
2778extern void move_gap (ptrdiff_t);
2779extern void move_gap_both (ptrdiff_t, ptrdiff_t); 2778extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2780extern _Noreturn void buffer_overflow (void); 2779extern _Noreturn void buffer_overflow (void);
2781extern void make_gap (ptrdiff_t); 2780extern void make_gap (ptrdiff_t);
diff --git a/src/xml.c b/src/xml.c
index 5939c58a564..5a52b0c2a1e 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -180,8 +180,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
180 xmlDoc *doc; 180 xmlDoc *doc;
181 Lisp_Object result = Qnil; 181 Lisp_Object result = Qnil;
182 const char *burl = ""; 182 const char *burl = "";
183 ptrdiff_t bytes; 183 ptrdiff_t istart, iend, istart_byte, iend_byte;
184 ptrdiff_t istart, iend;
185 184
186 fn_xmlCheckVersion (LIBXML_VERSION); 185 fn_xmlCheckVersion (LIBXML_VERSION);
187 186
@@ -189,9 +188,11 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
189 188
190 istart = XINT (start); 189 istart = XINT (start);
191 iend = XINT (end); 190 iend = XINT (end);
191 istart_byte = CHAR_TO_BYTE (istart);
192 iend_byte = CHAR_TO_BYTE (iend);
192 193
193 if (istart < GPT && GPT < iend) 194 if (istart < GPT && GPT < iend)
194 move_gap (iend); 195 move_gap_both (iend, iend_byte);
195 196
196 if (! NILP (base_url)) 197 if (! NILP (base_url))
197 { 198 {
@@ -199,17 +200,15 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
199 burl = SSDATA (base_url); 200 burl = SSDATA (base_url);
200 } 201 }
201 202
202 bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart);
203
204 if (htmlp) 203 if (htmlp)
205 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 204 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
206 bytes, burl, "utf-8", 205 iend_byte - istart_byte, burl, "utf-8",
207 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 206 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
208 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
209 HTML_PARSE_NOBLANKS); 208 HTML_PARSE_NOBLANKS);
210 else 209 else
211 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 210 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
212 bytes, burl, "utf-8", 211 iend_byte - istart_byte, burl, "utf-8",
213 XML_PARSE_NONET|XML_PARSE_NOWARNING| 212 XML_PARSE_NONET|XML_PARSE_NOWARNING|
214 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
215 214