From 009836b97cdab2b79cfa26c83459db3fd91c94b0 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 14 Jan 2015 15:56:46 +0300 Subject: [PATCH] Never move gap in make_buffer_string_both. * editfns.c (make_buffer_string_both): If requested range intersects the gap, don't move the latter but copy in two regions, thus avoiding unnecessary relocation of buffer data. --- src/ChangeLog | 4 ++++ src/editfns.c | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4f7ef6ef03e..f07ad02272d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -21,6 +21,10 @@ (Fencode_time): ... adjusted user. (Fset_time_zone_rule): Use decode_time_zone. + * editfns.c (make_buffer_string_both): If requested range intersects + the gap, don't move the latter but copy in two regions, thus avoiding + unnecessary relocation of buffer data. + 2015-01-14 Paul Eggert Use bool for boolean in xmenu.c, xml.c diff --git a/src/editfns.c b/src/editfns.c index 9a159ba6581..621e841c3f5 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2624,15 +2624,34 @@ make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, ptrdiff_t end_byte, bool props) { Lisp_Object result, tem, tem1; + ptrdiff_t beg0, end0, beg1, end1, size; - if (start < GPT && GPT < end) - move_gap_both (start, start_byte); + if (start_byte < GPT_BYTE && GPT_BYTE < end_byte) + { + /* Two regions, before and after the gap. */ + beg0 = start_byte; + end0 = GPT_BYTE; + beg1 = GPT_BYTE + GAP_SIZE - BEG_BYTE; + end1 = end_byte + GAP_SIZE - BEG_BYTE; + } + else + { + /* The only region. */ + beg0 = start_byte; + end0 = end_byte; + beg1 = -1; + end1 = -1; + } if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) result = make_uninit_multibyte_string (end - start, end_byte - start_byte); else result = make_uninit_string (end - start); - memcpy (SDATA (result), BYTE_POS_ADDR (start_byte), end_byte - start_byte); + + size = end0 - beg0; + memcpy (SDATA (result), BYTE_POS_ADDR (beg0), size); + if (beg1 != -1) + memcpy (SDATA (result) + size, BEG_ADDR + beg1, end1 - beg1); /* If desired, update and copy the text properties. */ if (props) -- 2.11.4.GIT