aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorEli Zaretskii2021-08-17 15:31:53 +0300
committerEli Zaretskii2021-08-17 15:31:53 +0300
commit5f47d17d33948e3802843c3552be544e7c8e5cf1 (patch)
treea2e774b3f93e31f1de5785f62a5fe19a1682825f /src/coding.c
parent00fdf80e21909366fcba0eab84fe68c803a3a3eb (diff)
downloademacs-5f47d17d33948e3802843c3552be544e7c8e5cf1.tar.gz
emacs-5f47d17d33948e3802843c3552be544e7c8e5cf1.zip
Fix TTY display performance degradation due to many markers
* src/coding.c (encode_coding_object): Don't assume that src_object == dst_object means src_object is the current buffer. Add the missing commentary that explains the arguments. (Bug#49127)
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/coding.c b/src/coding.c
index 87b55aecc05..d027c7d5399 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -8250,6 +8250,39 @@ decode_coding_object (struct coding_system *coding,
8250} 8250}
8251 8251
8252 8252
8253/* Encode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in
8254 SRC_OBJECT into DST_OBJECT by coding context CODING.
8255
8256 SRC_OBJECT is a buffer, a string, or Qnil.
8257
8258 If it is a buffer, the text is at point of the buffer. FROM and TO
8259 are positions in the buffer.
8260
8261 If it is a string, the text is at the beginning of the string.
8262 FROM and TO are indices into the string.
8263
8264 If it is nil, the text is at coding->source. FROM and TO are
8265 indices into coding->source.
8266
8267 DST_OBJECT is a buffer, Qt, or Qnil.
8268
8269 If it is a buffer, the encoded text is inserted at point of the
8270 buffer. If the buffer is the same as SRC_OBJECT, the source text
8271 is replaced with the encoded text.
8272
8273 If it is Qt, a string is made from the encoded text, and set in
8274 CODING->dst_object. However, if CODING->raw_destination is non-zero,
8275 the encoded text is instead returned in CODING->destination as a C string,
8276 and the caller is responsible for freeing CODING->destination. This
8277 feature is meant to be used when the caller doesn't need the result as
8278 a Lisp string, and wants to avoid unnecessary consing of large strings.
8279
8280 If it is Qnil, the encoded text is stored at CODING->destination.
8281 The caller must allocate CODING->dst_bytes bytes at
8282 CODING->destination by xmalloc. If the encoded text is longer than
8283 CODING->dst_bytes, CODING->destination is reallocated by xrealloc
8284 (and CODING->dst_bytes is enlarged accordingly). */
8285
8253void 8286void
8254encode_coding_object (struct coding_system *coding, 8287encode_coding_object (struct coding_system *coding,
8255 Lisp_Object src_object, 8288 Lisp_Object src_object,
@@ -8275,11 +8308,14 @@ encode_coding_object (struct coding_system *coding,
8275 8308
8276 attrs = CODING_ID_ATTRS (coding->id); 8309 attrs = CODING_ID_ATTRS (coding->id);
8277 8310
8278 if (EQ (src_object, dst_object)) 8311 bool same_buffer = false;
8312 if (EQ (src_object, dst_object) && BUFFERP (src_object))
8279 { 8313 {
8280 struct Lisp_Marker *tail; 8314 struct Lisp_Marker *tail;
8281 8315
8282 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) 8316 same_buffer = true;
8317
8318 for (tail = BUF_MARKERS (XBUFFER (src_object)); tail; tail = tail->next)
8283 { 8319 {
8284 tail->need_adjustment 8320 tail->need_adjustment
8285 = tail->charpos == (tail->insertion_type ? from : to); 8321 = tail->charpos == (tail->insertion_type ? from : to);
@@ -8298,7 +8334,7 @@ encode_coding_object (struct coding_system *coding,
8298 else 8334 else
8299 insert_1_both ((char *) coding->source + from, chars, bytes, 0, 0, 0); 8335 insert_1_both ((char *) coding->source + from, chars, bytes, 0, 0, 0);
8300 8336
8301 if (EQ (src_object, dst_object)) 8337 if (same_buffer)
8302 { 8338 {
8303 set_buffer_internal (XBUFFER (src_object)); 8339 set_buffer_internal (XBUFFER (src_object));
8304 saved_pt = PT, saved_pt_byte = PT_BYTE; 8340 saved_pt = PT, saved_pt_byte = PT_BYTE;
@@ -8329,7 +8365,7 @@ encode_coding_object (struct coding_system *coding,
8329 { 8365 {
8330 code_conversion_save (0, 0); 8366 code_conversion_save (0, 0);
8331 set_buffer_internal (XBUFFER (src_object)); 8367 set_buffer_internal (XBUFFER (src_object));
8332 if (EQ (src_object, dst_object)) 8368 if (same_buffer)
8333 { 8369 {
8334 saved_pt = PT, saved_pt_byte = PT_BYTE; 8370 saved_pt = PT, saved_pt_byte = PT_BYTE;
8335 coding->src_object = del_range_1 (from, to, 1, 1); 8371 coding->src_object = del_range_1 (from, to, 1, 1);