summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-08-27 13:56:24 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-08-27 14:03:20 -0400
commitc6cf5ec6ae6420e902441289a5b7524a2322a664 (patch)
tree537a21dd534b83948b7e0de38e90ebf2f2fdb95e /eval.c
parent8a9b6497167626e768cab063e9d6c381523b3244 (diff)
downloadbfs-c6cf5ec6ae6420e902441289a5b7524a2322a664.tar.xz
Implement cost-based optimization
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/eval.c b/eval.c
index 21204d8..d455aeb 100644
--- a/eval.c
+++ b/eval.c
@@ -96,10 +96,7 @@ static time_t timespec_diff(const struct timespec *lhs, const struct timespec *r
return ret;
}
-/**
- * Perform a comparison.
- */
-static bool do_cmp(const struct expr *expr, long long n) {
+bool expr_cmp(const struct expr *expr, long long n) {
switch (expr->cmp_flag) {
case CMP_EXACT:
return n == expr->idata;
@@ -167,7 +164,7 @@ bool eval_acmtime(const struct expr *expr, struct eval_state *state) {
break;
}
- return do_cmp(expr, diff);
+ return expr_cmp(expr, diff);
}
/**
@@ -208,7 +205,7 @@ bool eval_used(const struct expr *expr, struct eval_state *state) {
time_t diff = timespec_diff(&statbuf->st_atim, &statbuf->st_ctim);
diff /= 60*60*24;
- return do_cmp(expr, diff);
+ return expr_cmp(expr, diff);
}
/**
@@ -220,7 +217,7 @@ bool eval_gid(const struct expr *expr, struct eval_state *state) {
return false;
}
- return do_cmp(expr, statbuf->st_gid);
+ return expr_cmp(expr, statbuf->st_gid);
}
/**
@@ -232,7 +229,7 @@ bool eval_uid(const struct expr *expr, struct eval_state *state) {
return false;
}
- return do_cmp(expr, statbuf->st_uid);
+ return expr_cmp(expr, statbuf->st_uid);
}
/**
@@ -323,7 +320,7 @@ bool eval_exit(const struct expr *expr, struct eval_state *state) {
* -depth N test.
*/
bool eval_depth(const struct expr *expr, struct eval_state *state) {
- return do_cmp(expr, state->ftwbuf->depth);
+ return expr_cmp(expr, state->ftwbuf->depth);
}
/**
@@ -420,7 +417,7 @@ bool eval_inum(const struct expr *expr, struct eval_state *state) {
return false;
}
- return do_cmp(expr, statbuf->st_ino);
+ return expr_cmp(expr, statbuf->st_ino);
}
/**
@@ -432,7 +429,7 @@ bool eval_links(const struct expr *expr, struct eval_state *state) {
return false;
}
- return do_cmp(expr, statbuf->st_nlink);
+ return expr_cmp(expr, statbuf->st_nlink);
}
/**
@@ -779,7 +776,7 @@ bool eval_size(const struct expr *expr, struct eval_state *state) {
return false;
}
- static off_t scales[] = {
+ static const off_t scales[] = {
[SIZE_BLOCKS] = 512,
[SIZE_BYTES] = 1,
[SIZE_WORDS] = 2,
@@ -792,7 +789,7 @@ bool eval_size(const struct expr *expr, struct eval_state *state) {
off_t scale = scales[expr->size_unit];
off_t size = (statbuf->st_size + scale - 1)/scale; // Round up
- return do_cmp(expr, size);
+ return expr_cmp(expr, size);
}
/**