From 37a1145410f7d61883ea689255ee7e564c2fb3d0 Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Wed, 19 Oct 2022 16:16:09 -0700 Subject: [PATCH] Rename all exported itree.h functions with the itree_ prefix For the most part, I replaced the interval_tree_ prefix with itree_, interval_node_ with itree_node_, etc. * src/alloc.c: Rename everywhere as appropriate. * src/alloc.c: ditto. * src/buffer.c: ditto. * src/buffer.h: ditto. * src/itree.c: ditto. * src/itree.h: ditto. --- src/alloc.c | 2 +- src/buffer.c | 26 +++++++++++++------------- src/buffer.h | 4 ++-- src/itree.c | 30 +++++++++++++++--------------- src/itree.h | 33 +++++++++++++++++---------------- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index a08249b1b11..f69c65dedc1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3712,7 +3712,7 @@ build_overlay (bool front_advance, bool rear_advance, PVEC_OVERLAY); Lisp_Object overlay = make_lisp_ptr (p, Lisp_Vectorlike); struct itree_node *node = xmalloc (sizeof (*node)); - interval_node_init (node, front_advance, rear_advance, overlay); + itree_node_init (node, front_advance, rear_advance, overlay); p->interval = node; p->buffer = NULL; set_overlay_plist (overlay, plist); diff --git a/src/buffer.c b/src/buffer.c index 228c6e60560..3286cd338ff 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -644,9 +644,9 @@ add_buffer_overlay (struct buffer *b, struct Lisp_Overlay *ov, { eassert (! ov->buffer); if (! b->overlays) - b->overlays = interval_tree_create (); + b->overlays = itree_create (); ov->buffer = b; - itree_insert_node (b->overlays, ov->interval, begin, end); + itree_insert (b->overlays, ov->interval, begin, end); } /* Copy overlays of buffer FROM to buffer TO. */ @@ -911,7 +911,7 @@ remove_buffer_overlay (struct buffer *b, struct Lisp_Overlay *ov) { eassert (b->overlays); eassert (ov->buffer == b); - interval_tree_remove (ov->buffer->overlays, ov->interval); + itree_remove (ov->buffer->overlays, ov->interval); ov->buffer = NULL; } @@ -951,7 +951,7 @@ delete_all_overlays (struct buffer *b) /* Where are the nodes freed ? --ap */ XOVERLAY (node->data)->buffer = NULL; } - interval_tree_clear (b->overlays); + itree_clear (b->overlays); } static void @@ -960,7 +960,7 @@ free_buffer_overlays (struct buffer *b) /* Actually this does not free any overlay, but the tree only. --ap */ if (b->overlays) { - interval_tree_destroy (b->overlays); + itree_destroy (b->overlays); b->overlays = NULL; } } @@ -980,7 +980,7 @@ set_overlays_multibyte (bool multibyte) struct itree_node **nodes = NULL; struct itree_tree *tree = current_buffer->overlays; - const intmax_t size = interval_tree_size (tree); + const intmax_t size = itree_size (tree); /* We can't use `interval_node_set_region` at the same time as we iterate over the itree, so we need an auxiliary storage @@ -999,8 +999,8 @@ set_overlays_multibyte (bool multibyte) if (multibyte) { - ptrdiff_t begin = interval_node_begin (tree, node); - ptrdiff_t end = interval_node_end (tree, node); + ptrdiff_t begin = itree_node_begin (tree, node); + ptrdiff_t end = itree_node_end (tree, node); /* This models the behavior of markers. (The behavior of text-intervals differs slightly.) */ @@ -1010,12 +1010,12 @@ set_overlays_multibyte (bool multibyte) while (end < Z_BYTE && !CHAR_HEAD_P (FETCH_BYTE (end))) end++; - interval_node_set_region (tree, node, BYTE_TO_CHAR (begin), + itree_node_set_region (tree, node, BYTE_TO_CHAR (begin), BYTE_TO_CHAR (end)); } else { - interval_node_set_region (tree, node, CHAR_TO_BYTE (node->begin), + itree_node_set_region (tree, node, CHAR_TO_BYTE (node->begin), CHAR_TO_BYTE (node->end)); } } @@ -3446,7 +3446,7 @@ adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length) but we may need to update the value of the overlay center. */ if (! current_buffer->overlays) return; - interval_tree_insert_gap (current_buffer->overlays, pos, length); + itree_insert_gap (current_buffer->overlays, pos, length); } void @@ -3454,7 +3454,7 @@ adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length) { if (! current_buffer->overlays) return; - interval_tree_delete_gap (current_buffer->overlays, pos, length); + itree_delete_gap (current_buffer->overlays, pos, length); } @@ -3594,7 +3594,7 @@ buffer. */) add_buffer_overlay (XBUFFER (buffer), XOVERLAY (overlay), n_beg, n_end); } else - interval_node_set_region (b->overlays, XOVERLAY (overlay)->interval, + itree_node_set_region (b->overlays, XOVERLAY (overlay)->interval, n_beg, n_end); /* If the overlay has changed buffers, do a thorough redisplay. */ diff --git a/src/buffer.h b/src/buffer.h index ee0c8dd8361..ce1b7b27b0f 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1398,7 +1398,7 @@ overlay_start (struct Lisp_Overlay *ov) { if (! ov->buffer) return -1; - return interval_node_begin (ov->buffer->overlays, ov->interval); + return itree_node_begin (ov->buffer->overlays, ov->interval); } INLINE ptrdiff_t @@ -1406,7 +1406,7 @@ overlay_end (struct Lisp_Overlay *ov) { if (! ov->buffer) return -1; - return interval_node_end (ov->buffer->overlays, ov->interval); + return itree_node_end (ov->buffer->overlays, ov->interval); } /* Return the start of OV in its buffer, or -1 if OV is not associated diff --git a/src/itree.c b/src/itree.c index 6d54a36c3bb..501226b7e28 100644 --- a/src/itree.c +++ b/src/itree.c @@ -511,7 +511,7 @@ interval_tree_validate (struct itree_tree *tree, struct itree_node *node) /* Initialize an allocated node. */ void -interval_node_init (struct itree_node *node, +itree_node_init (struct itree_node *node, bool front_advance, bool rear_advance, Lisp_Object data) { @@ -528,7 +528,7 @@ interval_node_init (struct itree_node *node, /* Return NODE's begin value, computing it if necessary. */ ptrdiff_t -interval_node_begin (struct itree_tree *tree, +itree_node_begin (struct itree_tree *tree, struct itree_node *node) { interval_tree_validate (tree, node); @@ -538,7 +538,7 @@ interval_node_begin (struct itree_tree *tree, /* Return NODE's end value, computing it if necessary. */ ptrdiff_t -interval_node_end (struct itree_tree *tree, +itree_node_end (struct itree_tree *tree, struct itree_node *node) { interval_tree_validate (tree, node); @@ -548,7 +548,7 @@ interval_node_end (struct itree_tree *tree, /* Allocate an interval_tree. Free with interval_tree_destroy. */ struct itree_tree* -interval_tree_create (void) +itree_create (void) { /* FIXME? Maybe avoid the initialization of itree_null in the same way that is used to call mem_init in alloc.c? It's not really @@ -556,14 +556,14 @@ interval_tree_create (void) itree_init (); struct itree_tree *tree = xmalloc (sizeof (*tree)); - interval_tree_clear (tree); + itree_clear (tree); return tree; } /* Reset the tree TREE to its empty state. */ void -interval_tree_clear (struct itree_tree *tree) +itree_clear (struct itree_tree *tree) { tree->root = NULL; tree->otick = 1; @@ -583,7 +583,7 @@ interval_tree_init (struct interval_tree *tree) /* Release a tree, freeing its allocated memory. */ void -interval_tree_destroy (struct itree_tree *tree) +itree_destroy (struct itree_tree *tree) { eassert (tree->root == NULL); /* if (tree->iter) @@ -594,7 +594,7 @@ interval_tree_destroy (struct itree_tree *tree) /* Return the number of nodes in TREE. */ intmax_t -interval_tree_size (struct itree_tree *tree) +itree_size (struct itree_tree *tree) { return tree->size; } @@ -821,7 +821,7 @@ interval_tree_insert (struct itree_tree *tree, struct itree_node *node) } void -itree_insert_node (struct itree_tree *tree, struct itree_node *node, +itree_insert (struct itree_tree *tree, struct itree_node *node, ptrdiff_t begin, ptrdiff_t end) { node->begin = begin; @@ -833,14 +833,14 @@ itree_insert_node (struct itree_tree *tree, struct itree_node *node, /* Safely modify a node's interval. */ void -interval_node_set_region (struct itree_tree *tree, +itree_node_set_region (struct itree_tree *tree, struct itree_node *node, ptrdiff_t begin, ptrdiff_t end) { interval_tree_validate (tree, node); if (begin != node->begin) { - interval_tree_remove (tree, node); + itree_remove (tree, node); node->begin = min (begin, PTRDIFF_MAX - 1); node->end = max (node->begin, end); interval_tree_insert (tree, node); @@ -1054,7 +1054,7 @@ interval_tree_transplant (struct itree_tree *tree, /* Remove NODE from TREE and return it. NODE must exist in TREE. */ struct itree_node* -interval_tree_remove (struct itree_tree *tree, struct itree_node *node) +itree_remove (struct itree_tree *tree, struct itree_node *node) { eassert (interval_tree_contains (tree, node)); eassert (check_tree (tree, true)); /* FIXME: Too expensive. */ @@ -1181,7 +1181,7 @@ itree_iterator_finish (struct itree_iterator *iter) front_advance setting. */ void -interval_tree_insert_gap (struct itree_tree *tree, +itree_insert_gap (struct itree_tree *tree, ptrdiff_t pos, ptrdiff_t length) { if (length <= 0 || tree->root == NULL) @@ -1201,7 +1201,7 @@ interval_tree_insert_gap (struct itree_tree *tree, interval_stack_push (saved, node); } for (int i = 0; i < saved->length; ++i) - interval_tree_remove (tree, nav_nodeptr (saved->nodes[i])); + itree_remove (tree, nav_nodeptr (saved->nodes[i])); /* We can't use an iterator here, because we can't effectively narrow AND shift some subtree at the same time. */ @@ -1265,7 +1265,7 @@ interval_tree_insert_gap (struct itree_tree *tree, intersecting it. */ void -interval_tree_delete_gap (struct itree_tree *tree, +itree_delete_gap (struct itree_tree *tree, ptrdiff_t pos, ptrdiff_t length) { if (length <= 0 || tree->root == NULL) diff --git a/src/itree.h b/src/itree.h index b4116a1fb75..3df07ac1b7e 100644 --- a/src/itree.h +++ b/src/itree.h @@ -75,10 +75,9 @@ struct itree_node adjustment before use as buffer positions. NOTE: BEGIN and END must not be modified while the node is part - of a tree. Use interval_tree_insert_gap and - interval_tree_delete_gap instead. + of a tree. Use itree_insert_gap and itree_delete_gap instead. - NOTE: The interval generators ensure nodes are clean before + NOTE: The interval iterators ensure nodes are clean before yielding them, so BEGIN and END may be safely used as buffer positions then. */ @@ -107,19 +106,21 @@ enum itree_order { ITREE_PRE_ORDER, }; -void interval_node_init (struct itree_node *, bool, bool, Lisp_Object); -ptrdiff_t interval_node_begin (struct itree_tree *, struct itree_node *); -ptrdiff_t interval_node_end (struct itree_tree *, struct itree_node *); -void interval_node_set_region (struct itree_tree *, struct itree_node *, ptrdiff_t, ptrdiff_t); -struct itree_tree *interval_tree_create (void); -void interval_tree_destroy (struct itree_tree *); -intmax_t interval_tree_size (struct itree_tree *); -void interval_tree_clear (struct itree_tree *); -void itree_insert_node (struct itree_tree *tree, struct itree_node *node, - ptrdiff_t begin, ptrdiff_t end); -struct itree_node *interval_tree_remove (struct itree_tree *, struct itree_node *); -void interval_tree_insert_gap (struct itree_tree *, ptrdiff_t, ptrdiff_t); -void interval_tree_delete_gap (struct itree_tree *, ptrdiff_t, ptrdiff_t); +void itree_node_init (struct itree_node *, bool, bool, Lisp_Object); +ptrdiff_t itree_node_begin (struct itree_tree *, struct itree_node *); +ptrdiff_t itree_node_end (struct itree_tree *, struct itree_node *); +void itree_node_set_region (struct itree_tree *, struct itree_node *, + ptrdiff_t, ptrdiff_t); +struct itree_tree *itree_create (void); +void itree_destroy (struct itree_tree *); +intmax_t itree_size (struct itree_tree *); +void itree_clear (struct itree_tree *); +void itree_insert (struct itree_tree *tree, struct itree_node *node, + ptrdiff_t begin, ptrdiff_t end); +struct itree_node *itree_remove (struct itree_tree *, + struct itree_node *); +void itree_insert_gap (struct itree_tree *, ptrdiff_t, ptrdiff_t); +void itree_delete_gap (struct itree_tree *, ptrdiff_t, ptrdiff_t); /* Iteration functions. Almost all code should use ITREE_FOREACH instead. */ -- 2.39.2