summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-11-02 10:09:24 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-11-04 12:26:38 -0500
commit9f3be47e4327561bda4a3714ddc00fe1ee159e2e (patch)
treee7cf5864626f8bfd46a041ec9fbe46067591ee03
parent6e961567434f50abf850963873988c3365098681 (diff)
downloadbfs-9f3be47e4327561bda4a3714ddc00fe1ee159e2e.tar.xz
expr: Get rid of the extra list node
We can now just use for_arena() to iterate over the allocated bfs_exprs.
-rw-r--r--src/ctx.c7
-rw-r--r--src/ctx.h4
-rw-r--r--src/expr.c3
-rw-r--r--src/expr.h2
4 files changed, 5 insertions, 11 deletions
diff --git a/src/ctx.c b/src/ctx.c
index 2c55a35..0f8db10 100644
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -44,8 +44,7 @@ struct bfs_ctx *bfs_ctx_new(void) {
return NULL;
}
- SLIST_INIT(&ctx->expr_list);
- ARENA_INIT(&ctx->expr_arena, struct bfs_expr);
+ ARENA_INIT(&ctx->exprs, struct bfs_expr);
ctx->maxdepth = INT_MAX;
ctx->flags = BFTW_RECOVER;
@@ -285,10 +284,10 @@ int bfs_ctx_free(struct bfs_ctx *ctx) {
cfclose(cerr);
free_colors(ctx->colors);
- for_slist (struct bfs_expr, expr, &ctx->expr_list, freelist) {
+ for_arena (struct bfs_expr, expr, &ctx->exprs) {
bfs_expr_clear(expr);
}
- arena_destroy(&ctx->expr_arena);
+ arena_destroy(&ctx->exprs);
for (size_t i = 0; i < ctx->npaths; ++i) {
free((char *)ctx->paths[i]);
diff --git a/src/ctx.h b/src/ctx.h
index be6e2af..db7556f 100644
--- a/src/ctx.h
+++ b/src/ctx.h
@@ -39,10 +39,8 @@ struct bfs_ctx {
struct bfs_expr *expr;
/** An expression for files to filter out. */
struct bfs_expr *exclude;
- /** A list of allocated expressions. */
- struct bfs_exprs expr_list;
/** bfs_expr arena. */
- struct arena expr_arena;
+ struct arena exprs;
/** -mindepth option. */
int mindepth;
diff --git a/src/expr.c b/src/expr.c
index ca37ffc..e10c61c 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -17,7 +17,7 @@
struct bfs_expr *bfs_expr_new(struct bfs_ctx *ctx, bfs_eval_fn *eval_fn, size_t argc, char **argv, enum bfs_kind kind) {
bfs_assert(kind != BFS_PATH);
- struct bfs_expr *expr = arena_alloc(&ctx->expr_arena);
+ struct bfs_expr *expr = arena_alloc(&ctx->exprs);
if (!expr) {
return NULL;
}
@@ -28,7 +28,6 @@ struct bfs_expr *bfs_expr_new(struct bfs_ctx *ctx, bfs_eval_fn *eval_fn, size_t
expr->argv = argv;
expr->kind = kind;
expr->probability = 0.5;
- SLIST_PREPEND(&ctx->expr_list, expr, freelist);
if (bfs_expr_is_parent(expr)) {
SLIST_INIT(&expr->children);
diff --git a/src/expr.h b/src/expr.h
index 871b120..cb561c8 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -108,8 +108,6 @@ struct bfs_exprs {
struct bfs_expr {
/** This expression's next sibling, if any. */
struct bfs_expr *next;
- /** The next allocated expression. */
- struct { struct bfs_expr *next; } freelist;
/** The function that evaluates this expression. */
bfs_eval_fn *eval_fn;