From 75bfb2614d310f0708619f66f9088784f5733c49 Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Sun, 16 Oct 2022 16:03:30 -0700 Subject: [PATCH] Rename itree iterators with itree_iterator prefix * src/itree.h: Rename struct interval_generator -> itree_iterator. Rename functions: itree_busy_p -> itree_iterator_busy_p, interval_tree_iter_start -> itree_iterator_start, interval_generator_narrow -> itree_iterator_narrow, interval_tree_iter_finish -> itree_iterator_finish, interval_generator_next -> itree_iterator_next. * src/itree.c: Use new names everywhere. * src/eval.c: ditto. --- src/eval.c | 2 +- src/itree.c | 43 +++++++++++++++++++++---------------------- src/itree.h | 34 ++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/eval.c b/src/eval.c index 37c25c79148..197eb6afcb3 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1711,7 +1711,7 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) Lisp_Object clause = Qnil; struct handler *h; - eassert (!itree_busy_p ()); + eassert (!itree_iterator_busy_p ()); if (gc_in_progress || waiting_for_input) emacs_abort (); diff --git a/src/itree.c b/src/itree.c index 15af56e806a..0ba9e662bc2 100644 --- a/src/itree.c +++ b/src/itree.c @@ -146,8 +146,8 @@ static void interval_tree_replace_child (struct interval_tree *, static void interval_tree_transplant (struct interval_tree *tree, struct interval_node *source, struct interval_node *dest); -static struct interval_generator * -interval_generator_create (struct interval_tree *); +static struct itree_iterator * +itree_iterator_create (struct interval_tree *); static void interval_tree_insert (struct interval_tree *, struct interval_node *); static bool null_safe_is_red (struct interval_node *node); static bool null_safe_is_black (struct interval_node *node); @@ -165,7 +165,7 @@ struct interval_stack }; /* State used when iterating interval. */ -struct interval_generator +struct itree_iterator { struct interval_stack *stack; ptrdiff_t begin; @@ -182,12 +182,12 @@ struct interval_generator are limited by the fact we don't allow modifying the tree at the same time, making the use of nested iterations quite rare anyway. So we just use a single global iterator instead for now. */ -static struct interval_generator *iter; +static struct itree_iterator *iter; static void itree_init (void) { - iter = interval_generator_create (NULL); + iter = itree_iterator_create (NULL); } struct check_subtree_result @@ -481,7 +481,7 @@ static void interval_tree_init (struct interval_tree *tree) { interval_tree_clear (tree); - /* tree->iter = interval_generator_create (tree); */ + /* tree->iter = itree_iterator_create (tree); */ } #endif @@ -491,7 +491,7 @@ interval_tree_destroy (struct interval_tree *tree) { eassert (tree->root == ITREE_NULL); /* if (tree->iter) - * interval_generator_destroy (tree->iter); */ + * itree_iterator_destroy (tree->iter); */ xfree (tree); } @@ -805,7 +805,7 @@ interval_tree_validate (struct interval_tree *tree, struct interval_node *node) } bool -itree_busy_p (void) +itree_iterator_busy_p (void) { return (iter && iter->running); } @@ -815,13 +815,12 @@ itree_busy_p (void) time. */ -struct interval_generator * -interval_tree_iter_start (struct interval_tree *tree, - ptrdiff_t begin, ptrdiff_t end, - enum interval_tree_order order, - const char* file, int line) +struct itree_iterator * +itree_iterator_start (struct interval_tree *tree, ptrdiff_t begin, + ptrdiff_t end, enum interval_tree_order order, + const char *file, int line) { - /* struct interval_generator *iter = tree->iter; */ + /* struct itree_iterator *iter = tree->iter; */ if (iter->running) { fprintf (stderr, @@ -847,7 +846,7 @@ interval_tree_iter_start (struct interval_tree *tree, /* Stop using the iterator. */ void -interval_tree_iter_finish (struct interval_generator *iter) +itree_iterator_finish (struct itree_iterator *iter) { eassert (iter->running); iter->running = false; @@ -1007,10 +1006,10 @@ interval_tree_delete_gap (struct interval_tree *tree, ptrdiff_t pos, ptrdiff_t l /* Allocate a new generator for TREE. */ -static struct interval_generator * -interval_generator_create (struct interval_tree *tree) +static struct itree_iterator * +itree_iterator_create (struct interval_tree *tree) { - struct interval_generator *g = xmalloc (sizeof *g); + struct itree_iterator *g = xmalloc (sizeof *g); /* 19 here just avoids starting with a silly-small stack. FIXME: Since this stack only needs to be about 2*max_depth in the worst case, we could completely pre-allocate it to something @@ -1046,7 +1045,7 @@ interval_node_intersects (const struct interval_node *node, started; or NULL if there are no more nodes. */ struct interval_node * -interval_generator_next (struct interval_generator *g) +itree_iterator_next (struct itree_iterator *g) { eassert (g->running); @@ -1105,7 +1104,7 @@ interval_generator_next (struct interval_generator *g) break; } } - /* Node may have been invalidated by interval_generator_narrow + /* Node may have been invalidated by itree_iterator_narrow after it was pushed: Check if it still intersects. */ } while (node && ! interval_node_intersects (node, g->begin, g->end)); @@ -1116,8 +1115,8 @@ interval_generator_next (struct interval_generator *g) the current one. I.E. it can't grow on either side. */ void -interval_generator_narrow (struct interval_generator *g, - ptrdiff_t begin, ptrdiff_t end) +itree_iterator_narrow (struct itree_iterator *g, + ptrdiff_t begin, ptrdiff_t end) { eassert (g->running); eassert (begin >= g->begin); diff --git a/src/itree.h b/src/itree.h index 0e2e7d1f81f..f98f028ea52 100644 --- a/src/itree.h +++ b/src/itree.h @@ -32,8 +32,8 @@ along with GNU Emacs. If not, see . */ node.end directly, is while the node is not part of any tree. NOTE: It is safe to read node.begin and node.end directly, if the - node came from a generator, because it validates the nodes it - returns as a side-effect. + node came from an iterator, because it validates the nodes it + returns as a side-effect. See ITREE_FOREACH. */ struct interval_node; @@ -122,14 +122,20 @@ void interval_tree_clear (struct interval_tree *); void itree_insert_node (struct interval_tree *tree, struct interval_node *node, ptrdiff_t begin, ptrdiff_t end); struct interval_node *interval_tree_remove (struct interval_tree *, struct interval_node *); -struct interval_generator *interval_tree_iter_start (struct interval_tree *, ptrdiff_t, ptrdiff_t, enum interval_tree_order, - const char* file, int line); -void interval_generator_narrow (struct interval_generator *, ptrdiff_t, ptrdiff_t); -void interval_tree_iter_finish (struct interval_generator *); -struct interval_node *interval_generator_next (struct interval_generator *); void interval_tree_insert_gap (struct interval_tree *, ptrdiff_t, ptrdiff_t); void interval_tree_delete_gap (struct interval_tree *, ptrdiff_t, ptrdiff_t); -bool itree_busy_p (void); + +/* Iteration functions. Almost all code should use ITREE_FOREACH + instead. */ +bool itree_iterator_busy_p (void); +struct itree_iterator * +itree_iterator_start (struct interval_tree *tree, ptrdiff_t begin, + ptrdiff_t end, enum interval_tree_order order, + const char *file, int line); +void itree_iterator_narrow (struct itree_iterator *, ptrdiff_t, + ptrdiff_t); +void itree_iterator_finish (struct itree_iterator *); +struct interval_node *itree_iterator_next (struct itree_iterator *); /* Iterate over the intervals between BEG and END in the tree T. N will hold successive nodes. ORDER can be one of : `ASCENDING`, @@ -162,16 +168,16 @@ bool itree_busy_p (void); if (!t) \ { } \ else \ - for (struct interval_generator *itree_iter_ \ - = interval_tree_iter_start (t, beg, end, ITREE_##order, \ + for (struct itree_iterator *itree_iter_ \ + = itree_iterator_start (t, beg, end, ITREE_##order, \ __FILE__, __LINE__); \ - ((n = interval_generator_next (itree_iter_)) \ - || (interval_tree_iter_finish (itree_iter_), false));) + ((n = itree_iterator_next (itree_iter_)) \ + || (itree_iterator_finish (itree_iter_), false));) #define ITREE_FOREACH_ABORT() \ - interval_tree_iter_finish (itree_iter_) + itree_iterator_finish (itree_iter_) #define ITREE_FOREACH_NARROW(beg, end) \ - interval_generator_narrow (itree_iter_, beg, end) + itree_iterator_narrow (itree_iter_, beg, end) #endif -- 2.39.2