* Simplify delete_all_overlays
@ 2012-07-05 5:43 Dmitry Antipov
0 siblings, 0 replies; only message in thread
From: Dmitry Antipov @ 2012-07-05 5:43 UTC (permalink / raw)
To: Emacs development discussions
[-- Attachment #1: Type: text/plain, Size: 209 bytes --]
In delete_all_overlays, can we avoid unchaining overlays one by one?
This looks redundant since both overlay lists are destroyed anyway.
BTW, is there an "official policy" about using comma operator?
Dmitry
[-- Attachment #2: delete_all_overlays.patch --]
[-- Type: text/plain, Size: 2908 bytes --]
=== modified file 'src/buffer.c'
--- src/buffer.c 2012-07-04 15:49:46 +0000
+++ src/buffer.c 2012-07-05 05:22:03 +0000
@@ -667,27 +667,32 @@
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;
-
- /* `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)
- {
- XSETMISC (overlay, b->overlays_before);
- Fdelete_overlay (overlay);
- }
- while (b->overlays_after)
- {
- XSETMISC (overlay, b->overlays_after);
- Fdelete_overlay (overlay);
- }
- eassert (b->overlays_before == NULL);
- eassert (b->overlays_after == NULL);
+ struct Lisp_Overlay *ov, *next;
+
+ for (ov = b->overlays_before; ov; ov = next)
+ drop_overlay (b, ov), next = ov->next, ov->next = NULL;
+
+ for (ov = b->overlays_after; ov; ov = next)
+ drop_overlay (b, ov), next = ov->next, ov->next = NULL;
+
+ b->overlays_before = b->overlays_after = NULL;
}
/* Reinitialize everything about a buffer except its name and contents
@@ -3821,11 +3826,7 @@
= 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
=== modified file 'src/minibuf.c'
--- src/minibuf.c 2012-06-28 12:29:37 +0000
+++ src/minibuf.c 2012-07-05 05:12:04 +0000
@@ -804,10 +804,9 @@
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 ());
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-07-05 5:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-05 5:43 Simplify delete_all_overlays Dmitry Antipov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.