From 041a49a645d9bbe7f249083d9065076bc8ccaa45 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 6 Jul 2012 08:42:30 +0400 Subject: [PATCH] Do not use Fdelete_overlay in delete_all_overlays to avoid redundant calls to unchain_overlay. * buffer.c (drop_overlay): New function. (delete_all_overlays, Fdelete_overlay): Use it. * minibuf.c (get_minibuffer): Fix comment. --- src/ChangeLog | 8 ++++++++ src/buffer.c | 45 +++++++++++++++++++++++++++------------------ src/minibuf.c | 7 +++---- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index af51c9a100..c8a9b3f8b0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2012-07-06 Dmitry Antipov + + Do not use Fdelete_overlay in delete_all_overlays + to avoid redundant calls to unchain_overlay. + * buffer.c (drop_overlay): New function. + (delete_all_overlays, Fdelete_overlay): Use it. + * minibuf.c (get_minibuffer): Fix comment. + 2012-07-06 Paul Eggert Port to OpenBSD 5.1 amd64. diff --git a/src/buffer.c b/src/buffer.c index 838932db4d..f73d2d0753 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -667,27 +667,40 @@ CLONE nil means the indirect buffer's state is reset to default values. */) return buf; } +/* Mark OV as no longer associated with B. */ + +static void +drop_overlay (struct buffer *b, struct Lisp_Overlay *ov) +{ + eassert (b == XBUFFER (Fmarker_buffer (ov->start))); + modify_overlay (b, marker_position (ov->start), marker_position (ov->end)); + Fset_marker (ov->start, Qnil, Qnil); + Fset_marker (ov->end, Qnil, Qnil); + +} + +/* Delete all overlays of B and reset it's overlay lists. */ + void delete_all_overlays (struct buffer *b) { - Lisp_Object overlay; + struct Lisp_Overlay *ov, *next; - /* `reset_buffer' blindly sets the list of overlays to NULL, so we - have to empty the list, otherwise we end up with overlays that - think they belong to this buffer while the buffer doesn't know about - them any more. */ - while (b->overlays_before) + for (ov = b->overlays_before; ov; ov = next) { - XSETMISC (overlay, b->overlays_before); - Fdelete_overlay (overlay); + drop_overlay (b, ov); + next = ov->next; + ov->next = NULL; } - while (b->overlays_after) + + for (ov = b->overlays_after; ov; ov = next) { - XSETMISC (overlay, b->overlays_after); - Fdelete_overlay (overlay); + drop_overlay (b, ov); + next = ov->next; + ov->next = NULL; } - eassert (b->overlays_before == NULL); - eassert (b->overlays_after == NULL); + + b->overlays_before = b->overlays_after = NULL; } /* Reinitialize everything about a buffer except its name and contents @@ -3820,11 +3833,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); eassert (XOVERLAY (overlay)->next == NULL); - modify_overlay (b, - marker_position (OVERLAY_START (overlay)), - marker_position (OVERLAY_END (overlay))); - Fset_marker (OVERLAY_START (overlay), Qnil, Qnil); - Fset_marker (OVERLAY_END (overlay), Qnil, Qnil); + drop_overlay (b, XOVERLAY (overlay)); /* When deleting an overlay with before or after strings, turn off display optimizations for the affected buffer, on the basis that diff --git a/src/minibuf.c b/src/minibuf.c index 050a22a418..89390aeb0b 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -804,10 +804,9 @@ get_minibuffer (EMACS_INT depth) else { ptrdiff_t count = SPECPDL_INDEX (); - /* `reset_buffer' blindly sets the list of overlays to NULL, so we - have to empty the list, otherwise we end up with overlays that - think they belong to this buffer while the buffer doesn't know about - them any more. */ + /* We have to empty both overlay lists. Otherwise we end + up with overlays that think they belong to this buffer + while the buffer doesn't know about them any more. */ delete_all_overlays (XBUFFER (buf)); reset_buffer (XBUFFER (buf)); record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); -- 2.20.1