aboutsummaryrefslogtreecommitdiffstats
path: root/src/intervals.c
diff options
context:
space:
mode:
authorStefan Monnier2001-10-12 21:53:44 +0000
committerStefan Monnier2001-10-12 21:53:44 +0000
commit19d4e9a77301642cf131d10ffce88f4ea5c37d78 (patch)
tree20f804bc9b77fdbbe95313727dc2e90a81cd6ecd /src/intervals.c
parent65550192d8acbff6845f79ed3f2b260fd611779d (diff)
downloademacs-19d4e9a77301642cf131d10ffce88f4ea5c37d78.tar.gz
emacs-19d4e9a77301642cf131d10ffce88f4ea5c37d78.zip
(traverse_intervals): Use less stack space.
(traverse_intervals_noorder): New function. (search_for_interval, count_intervals): Use it.
Diffstat (limited to 'src/intervals.c')
-rw-r--r--src/intervals.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/intervals.c b/src/intervals.c
index 06d6d5995bd..868d60bccf3 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -188,6 +188,30 @@ intervals_equal (i0, i1)
188 188
189 189
190/* Traverse an interval tree TREE, performing FUNCTION on each node. 190/* Traverse an interval tree TREE, performing FUNCTION on each node.
191 No guarantee is made about the order of traversal.
192 Pass FUNCTION two args: an interval, and ARG. */
193
194void
195traverse_intervals_noorder (tree, function, arg)
196 INTERVAL tree;
197 void (* function) P_ ((INTERVAL, Lisp_Object));
198 Lisp_Object arg;
199{
200 /* Minimize stack usage. */
201 while (!NULL_INTERVAL_P (tree))
202 {
203 (*function) (tree, arg);
204 if (NULL_INTERVAL_P (tree->right))
205 tree = tree->left;
206 else
207 {
208 traverse_intervals_noorder (tree->left, function, arg);
209 tree = tree->right;
210 }
211 }
212}
213
214/* Traverse an interval tree TREE, performing FUNCTION on each node.
191 Pass FUNCTION two args: an interval, and ARG. */ 215 Pass FUNCTION two args: an interval, and ARG. */
192 216
193void 217void
@@ -197,15 +221,14 @@ traverse_intervals (tree, position, depth, function, arg)
197 void (* function) P_ ((INTERVAL, Lisp_Object)); 221 void (* function) P_ ((INTERVAL, Lisp_Object));
198 Lisp_Object arg; 222 Lisp_Object arg;
199{ 223{
200 if (NULL_INTERVAL_P (tree)) 224 while (!NULL_INTERVAL_P (tree))
201 return; 225 {
202 226 traverse_intervals (tree->left, position, depth + 1, function, arg);
203 traverse_intervals (tree->left, position, depth + 1, function, arg); 227 position += LEFT_TOTAL_LENGTH (tree);
204 position += LEFT_TOTAL_LENGTH (tree); 228 tree->position = position;
205 tree->position = position; 229 (*function) (tree, arg);
206 (*function) (tree, arg); 230 position += LENGTH (tree); tree = tree->right; depth++;
207 position += LENGTH (tree); 231 }
208 traverse_intervals (tree->right, position, depth + 1, function, arg);
209} 232}
210 233
211#if 0 234#if 0
@@ -236,7 +259,7 @@ search_for_interval (i, tree)
236 icount = 0; 259 icount = 0;
237 search_interval = i; 260 search_interval = i;
238 found_interval = NULL_INTERVAL; 261 found_interval = NULL_INTERVAL;
239 traverse_intervals (tree, 1, 0, &check_for_interval, Qnil); 262 traverse_intervals_noorder (tree, &check_for_interval, Qnil);
240 return found_interval; 263 return found_interval;
241} 264}
242 265
@@ -258,7 +281,7 @@ count_intervals (i)
258 icount = 0; 281 icount = 0;
259 idepth = 0; 282 idepth = 0;
260 zero_length = 0; 283 zero_length = 0;
261 traverse_intervals (i, 1, 0, &inc_interval_count, Qnil); 284 traverse_intervals_noorder (i, &inc_interval_count, Qnil);
262 285
263 return icount; 286 return icount;
264} 287}
@@ -285,7 +308,7 @@ root_interval (interval)
285 c c 308 c c
286*/ 309*/
287 310
288static INTERVAL 311static INLINE INTERVAL
289rotate_right (interval) 312rotate_right (interval)
290 INTERVAL interval; 313 INTERVAL interval;
291{ 314{
@@ -331,7 +354,7 @@ rotate_right (interval)
331 c c 354 c c
332*/ 355*/
333 356
334static INTERVAL 357static INLINE INTERVAL
335rotate_left (interval) 358rotate_left (interval)
336 INTERVAL interval; 359 INTERVAL interval;
337{ 360{