summaryrefslogtreecommitdiffstats
path: root/filter.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-11-01 20:27:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-11-01 20:27:42 -0700
commit1a71176dca92298cbb4e93530be2a79c80956471 (patch)
tree67c9b7e0d943cf26f89776b58c3b5060ed48f073 /filter.c
parentfcd748480a76b3fef7586483b29fc5281e405e1f (diff)
downloadtxr-1a71176dca92298cbb4e93530be2a79c80956471.tar.gz
txr-1a71176dca92298cbb4e93530be2a79c80956471.tar.bz2
txr-1a71176dca92298cbb4e93530be2a79c80956471.zip
lib: use stack-allocated hash iterators everywhere.
* eval.c (op_dohash): Use hash_iter instead of consing up heap-allocated hash iterator. * filter.c (trie_compress, regex_from_trie): Likewise. * hash.c (hash_equal_op, hash_hash_op, hash_print_op): Likewise. * lib.c (package_local_symbols, package_foreign_symbols, find_max, find_if, rfind_if, populate_obj_hash): Likewise. * parser.c (circ_backpatch, get_visible_syms): Likewise. * struct.c (method_name, get_slot_syms): Likewise.
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/filter.c b/filter.c
index ce03f575..725939ae 100644
--- a/filter.c
+++ b/filter.c
@@ -94,14 +94,15 @@ static void trie_compress(loc ptrie)
if (zerop(count)) {
set(ptrie, value);
} else if (count == one && nilp(value)) {
- val iter = hash_begin(trie);
- val cell = hash_next(iter);
+ struct hash_iter hi;
+ val cell = (us_hash_iter_init(&hi, trie), hash_iter_next(&hi));
set(ptrie, cons(us_car(cell), us_cdr(cell)));
trie_compress(cdr_l(deref(ptrie)));
} else {
- val cell, iter = hash_begin(trie);
-
- for (cell = hash_next(iter); cell; cell = hash_next(iter))
+ val cell;
+ struct hash_iter hi;
+ us_hash_iter_init(&hi, trie);
+ for (cell = hash_iter_next(&hi); cell; cell = hash_iter_next(&hi))
trie_compress(mkloc(*us_cdr_p(cell), cell));
}
} else if (consp(trie)) {
@@ -146,9 +147,12 @@ static val regex_from_trie(val trie)
return nil;
} else {
list_collect_decl (out, ptail);
- val iter = hash_begin(trie);
val cell;
- while ((cell = hash_next(iter)) != nil) {
+ struct hash_iter hi;
+
+ us_hash_iter_init(&hi, trie);
+
+ while ((cell = hash_iter_next(&hi)) != nil) {
val rx = regex_from_trie(us_cdr(cell));
ptail = list_collect(ptail,
if3(consp(rx) && car(rx) == compound_s,