From 757c116f6b0bc2d8e81aef18f8eada27ca8745a1 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 29 Sep 2022 16:15:01 -0400 Subject: [PATCH] free_buffer_overlays: Move nearer to its sole caller * src/buffer.c (free_buffer_overlays): Move from `buffer.h`. * src/buffer.h (free_buffer_overlays): Move to `buffer.c`. * src/itree.c (interval_tree_iter_narrow, interval_tree_iter_finish) (interval_tree_iter_next): Prefer `eassert`. --- src/buffer.c | 12 ++++++++++++ src/buffer.h | 14 ------------- src/itree.c | 55 +++++++++++++++++++++++++--------------------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 879e14be960..2f026584bbf 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -932,6 +932,18 @@ delete_all_overlays (struct buffer *b) interval_tree_clear (b->overlays); } +static void +free_buffer_overlays (struct buffer *b) +{ + /* Actually this does not free any overlay, but the tree only. --ap */ + eassert (! b->overlays || 0 == interval_tree_size (b->overlays)); + if (b->overlays) + { + interval_tree_destroy (b->overlays); + b->overlays = NULL; + } +} + /* Adjust the position of overlays in the current buffer according to MULTIBYTE. diff --git a/src/buffer.h b/src/buffer.h index 097283be671..447be06594c 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1424,20 +1424,6 @@ maybe_alloc_buffer_overlays (struct buffer *b) b->overlays = interval_tree_create (); } -/* FIXME: Actually this does not free any overlay, but the tree - only. --ap */ - -INLINE void -free_buffer_overlays (struct buffer *b) -{ - eassert (! b->overlays || 0 == interval_tree_size (b->overlays)); - if (b->overlays) - { - interval_tree_destroy (b->overlays); - b->overlays = NULL; - } -} - INLINE void add_buffer_overlay (struct buffer *b, struct Lisp_Overlay *ov) { diff --git a/src/itree.c b/src/itree.c index bdaa3fe09bb..7c2602683c4 100644 --- a/src/itree.c +++ b/src/itree.c @@ -94,26 +94,26 @@ along with GNU Emacs. If not, see . */ incremented whenever some node's offset has changed. */ -static struct interval_node *interval_tree_validate(struct interval_tree *, struct interval_node *); -static void interval_generator_ensure_space(struct interval_generator *); -static bool interval_node_intersects(const struct interval_node *, ptrdiff_t, ptrdiff_t); -static int interval_tree_max_height(const struct interval_tree *); -static struct interval_stack *interval_stack_create(intmax_t); -static void interval_stack_destroy(struct interval_stack *); -static void interval_stack_clear(struct interval_stack *); -static void interval_stack_ensure_space(struct interval_stack *, intmax_t); -static void interval_stack_push(struct interval_stack *, struct interval_node *); -static void interval_stack_push_flagged(struct interval_stack *, struct interval_node *, bool); -static struct interval_node *interval_stack_pop(struct interval_stack *); -static void interval_tree_update_limit(const struct interval_tree *, struct interval_node *); -static void interval_tree_inherit_offset(const struct interval_tree *, struct interval_node *); -static void interval_tree_propagate_limit(const struct interval_tree *, struct interval_node *); -static void interval_tree_rotate_left(struct interval_tree *, struct interval_node *); -static void interval_tree_rotate_right(struct interval_tree *, struct interval_node *); -static void interval_tree_insert_fix(struct interval_tree *, struct interval_node *); -static void interval_tree_remove_fix(struct interval_tree *, struct interval_node *); -static void interval_tree_transplant(struct interval_tree *, struct interval_node *, struct interval_node *); -static struct interval_node *interval_tree_subtree_min(const struct interval_tree *, struct interval_node *); +static struct interval_node *interval_tree_validate (struct interval_tree *, struct interval_node *); +static void interval_generator_ensure_space (struct interval_generator *); +static bool interval_node_intersects (const struct interval_node *, ptrdiff_t, ptrdiff_t); +static int interval_tree_max_height (const struct interval_tree *); +static struct interval_stack *interval_stack_create (intmax_t); +static void interval_stack_destroy (struct interval_stack *); +static void interval_stack_clear (struct interval_stack *); +static void interval_stack_ensure_space (struct interval_stack *, intmax_t); +static void interval_stack_push (struct interval_stack *, struct interval_node *); +static void interval_stack_push_flagged (struct interval_stack *, struct interval_node *, bool); +static struct interval_node *interval_stack_pop (struct interval_stack *); +static void interval_tree_update_limit (const struct interval_tree *, struct interval_node *); +static void interval_tree_inherit_offset (const struct interval_tree *, struct interval_node *); +static void interval_tree_propagate_limit (const struct interval_tree *, struct interval_node *); +static void interval_tree_rotate_left (struct interval_tree *, struct interval_node *); +static void interval_tree_rotate_right (struct interval_tree *, struct interval_node *); +static void interval_tree_insert_fix (struct interval_tree *, struct interval_node *); +static void interval_tree_remove_fix (struct interval_tree *, struct interval_node *); +static void interval_tree_transplant (struct interval_tree *, struct interval_node *, struct interval_node *); +static struct interval_node *interval_tree_subtree_min (const struct interval_tree *, struct interval_node *); static struct interval_generator* interval_generator_create (struct interval_tree *); static void interval_generator_destroy (struct interval_generator *); static void interval_generator_reset (struct interval_generator *, @@ -124,7 +124,7 @@ interval_generator_narrow (struct interval_generator *g, ptrdiff_t begin, ptrdiff_t end); static inline struct interval_node* interval_generator_next (struct interval_generator *g); -static inline void interval_tree_iter_ensure_space(struct interval_tree *); +static inline void interval_tree_iter_ensure_space (struct interval_tree *); @@ -454,11 +454,10 @@ interval_tree_iter_start (struct interval_tree *tree, interval can only shrink, but never grow.*/ inline void -interval_tree_iter_narrow(struct interval_tree *tree, - ptrdiff_t begin, ptrdiff_t end) +interval_tree_iter_narrow (struct interval_tree *tree, + ptrdiff_t begin, ptrdiff_t end) { - if (! tree->iter_running) - emacs_abort (); + eassert (tree->iter_running); interval_generator_narrow (tree->iter, begin, end); } @@ -467,8 +466,7 @@ interval_tree_iter_narrow(struct interval_tree *tree, void interval_tree_iter_finish (struct interval_tree *tree) { - if (! tree->iter_running) - emacs_abort (); + eassert (tree->iter_running); tree->iter_running = false; } @@ -478,8 +476,7 @@ interval_tree_iter_finish (struct interval_tree *tree) inline struct interval_node* interval_tree_iter_next (struct interval_tree *tree) { - if (! tree->iter_running) - emacs_abort (); + eassert (tree->iter_running); return interval_generator_next (tree->iter); } -- 2.39.2