diff options
| author | Stefan Monnier | 2022-11-17 18:09:37 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2022-11-17 18:09:37 -0500 |
| commit | 091e0f04ffe494ee4cddb67670f0c495a7c9b691 (patch) | |
| tree | 3e93d67eed88aeea94cc78951e987fedffd7d8ea /src/itree.h | |
| parent | fb7f1864da4aa4c09756cfe47db6c56b4e87bd14 (diff) | |
| download | emacs-scratch/noverlay.tar.gz emacs-scratch/noverlay.zip | |
itree.c: Get rid of the old iterator codescratch/noverlay
Only use the new iterator which relies on a fixed size (and small)
state in the iterator.
This makes non-local exits safe within ITREE_FOREACH loops.
* src/itree.c (make_nav, nav_nodeptr, nav_flag, itree_stack_clear)
(itree_stack_push_flagged): Delete functions.
(nodeptr_and_flag): Delete type.
(struct itree_stack): Make the array hold plain pointers instead.
(itree_stack_push): Inline the former code of `itree_stack_push_flagged`.
(itree_stack_pop): Change return type.
(itree_contains): Don't call `ITREE_FOREACH_ABORT` any more.
(itree_insert_gap): Simplify access to the stack of nodes.
(itree_delete_gap, itree_insert_gap): Adjust code to new return type of
`itree_stack_pop`.
(itree_iterator_finish): Delete function.
(itree_iterator_start): Don't setup the `stack` field any more.
(itree_iterator_next): Delete function.
(itree_iter_next): Rename to `itree_iterator_next` and make it non-static.
(itree_iterator_narrow): Don't check the `running` flag any more.
* src/itree.h (itree_iterator_finish): Remove declaration.
(struct itree_iterator): Remove the `stack` and `running` fields.
(ITREE_FOREACH_ABORT): Delete macro.
(ITREE_FOREACH): Don't call `itree_iterator_finish` any more.
* src/xdisp.c (strings_with_newlines):
* src/buffer.c (overlays_in, next_overlay_change, overlay_touches_p):
Don't call `ITREE_FOREACH_ABORT` any more.
Diffstat (limited to 'src/itree.h')
| -rw-r--r-- | src/itree.h | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/itree.h b/src/itree.h index 37cd423d34a..291fa53fd30 100644 --- a/src/itree.h +++ b/src/itree.h | |||
| @@ -132,24 +132,21 @@ extern struct itree_iterator *itree_iterator_start (struct itree_iterator *, | |||
| 132 | enum itree_order); | 132 | enum itree_order); |
| 133 | extern void itree_iterator_narrow (struct itree_iterator *, ptrdiff_t, | 133 | extern void itree_iterator_narrow (struct itree_iterator *, ptrdiff_t, |
| 134 | ptrdiff_t); | 134 | ptrdiff_t); |
| 135 | extern void itree_iterator_finish (struct itree_iterator *); | ||
| 136 | extern struct itree_node *itree_iterator_next (struct itree_iterator *); | 135 | extern struct itree_node *itree_iterator_next (struct itree_iterator *); |
| 137 | 136 | ||
| 138 | /* State used when iterating interval. */ | 137 | /* State used when iterating interval. */ |
| 139 | struct itree_iterator | 138 | struct itree_iterator |
| 140 | { | 139 | { |
| 141 | struct itree_node *node; /* FIXME: It should be either `node` or `stack`. */ | 140 | struct itree_node *node; |
| 142 | struct itree_stack *stack; | ||
| 143 | ptrdiff_t begin; | 141 | ptrdiff_t begin; |
| 144 | ptrdiff_t end; | 142 | ptrdiff_t end; |
| 145 | uintmax_t otick; /* A copy of the tree's `otick`. */ | 143 | uintmax_t otick; /* A copy of the tree's `otick`. */ |
| 146 | enum itree_order order; | 144 | enum itree_order order; |
| 147 | bool running; | ||
| 148 | }; | 145 | }; |
| 149 | 146 | ||
| 150 | /* Iterate over the intervals between BEG and END in the tree T. | 147 | /* Iterate over the intervals between BEG and END in the tree T. |
| 151 | N will hold successive nodes. ORDER can be one of : `ASCENDING`, | 148 | N will hold successive nodes. ORDER can be one of : `ASCENDING`, |
| 152 | `DESCENDING`, or `PRE_ORDER`. | 149 | `DESCENDING`, `POST_ORDER`, or `PRE_ORDER`. |
| 153 | It should be used as: | 150 | It should be used as: |
| 154 | 151 | ||
| 155 | ITREE_FOREACH (n, t, beg, end, order) | 152 | ITREE_FOREACH (n, t, beg, end, order) |
| @@ -160,9 +157,6 @@ struct itree_iterator | |||
| 160 | BEWARE: | 157 | BEWARE: |
| 161 | - The expression T may be evaluated more than once, so make sure | 158 | - The expression T may be evaluated more than once, so make sure |
| 162 | it is cheap and pure. | 159 | it is cheap and pure. |
| 163 | - If you need to exit the loop early, you *have* to call `ITREE_ABORT` | ||
| 164 | just before exiting (e.g. with `break` or `return`). | ||
| 165 | - Non-local exits are not supported within the body of the loop. | ||
| 166 | - Don't modify the tree during the iteration. | 160 | - Don't modify the tree during the iteration. |
| 167 | */ | 161 | */ |
| 168 | #define ITREE_FOREACH(n, t, beg, end, order) \ | 162 | #define ITREE_FOREACH(n, t, beg, end, order) \ |
| @@ -179,11 +173,7 @@ struct itree_iterator | |||
| 179 | *itree_iter_ \ | 173 | *itree_iter_ \ |
| 180 | = itree_iterator_start (&itree_local_iter_, \ | 174 | = itree_iterator_start (&itree_local_iter_, \ |
| 181 | t, beg, end, ITREE_##order); \ | 175 | t, beg, end, ITREE_##order); \ |
| 182 | ((n = itree_iterator_next (itree_iter_)) \ | 176 | ((n = itree_iterator_next (itree_iter_)));) |
| 183 | || (itree_iterator_finish (itree_iter_), false));) | ||
| 184 | |||
| 185 | #define ITREE_FOREACH_ABORT() \ | ||
| 186 | itree_iterator_finish (itree_iter_) | ||
| 187 | 177 | ||
| 188 | #define ITREE_FOREACH_NARROW(beg, end) \ | 178 | #define ITREE_FOREACH_NARROW(beg, end) \ |
| 189 | itree_iterator_narrow (itree_iter_, beg, end) | 179 | itree_iterator_narrow (itree_iter_, beg, end) |