Discussion:
[PATCH] fix live filtering for integer expressions
Johannes Weißl
2011-04-03 21:32:26 UTC
Permalink
---
expr.c | 24 ++++++++++++++++++++++++
expr.h | 2 ++
lib.c | 14 +-------------
3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/expr.c b/expr.c
index 6b52954..cfaa6bd 100644
--- a/expr.c
+++ b/expr.c
@@ -823,6 +823,30 @@ unsigned int expr_get_match_type(struct expr *expr)
return 0;
}

+int expr_is_harmless(const struct expr *expr)
+{
+ switch (expr->type) {
+ case EXPR_OR:
+ case EXPR_NOT:
+ return 0;
+ case EXPR_AND:
+ expr = expr->right;
+ default:
+ break;
+ }
+ if (expr->type == EXPR_INT) {
+ switch (expr->eint.op) {
+ case IOP_LT:
+ case IOP_EQ:
+ case IOP_LE:
+ return 0;
+ default:
+ return 1;
+ }
+ }
+ return 1;
+}
+
int expr_eval(struct expr *expr, struct track_info *ti)
{
enum expr_type type = expr->type;
diff --git a/expr.h b/expr.h
index eeebaeb..5800e91 100644
--- a/expr.h
+++ b/expr.h
@@ -57,5 +57,7 @@ const char *expr_error(void);
int expr_is_short(const char *str);

unsigned int expr_get_match_type(struct expr *expr);
+/* "harmless" expressions will reduce filter results when adding characters at the beginning/end */
+int expr_is_harmless(const struct expr *expr);

#endif
diff --git a/lib.c b/lib.c
index 1367731..101661f 100644
--- a/lib.c
+++ b/lib.c
@@ -536,18 +536,6 @@ static void restore_sel_track(void)
}
}

-/* "harmless" expressions will reduce filter results when adding characters at the beginning/end */
-static int is_harmless_expr(const char *str)
-{
- int i;
- const char *s = "!|-<";
- for (i = 0; s[i]; i++) {
- if (strchr(str, s[i]))
- return 0;
- }
- return 1;
-}
-
/* determine if filter results could grow, in which case all tracks must be cleared and re-added */
static int do_clear_before(const char *str, struct expr *expr)
{
@@ -557,7 +545,7 @@ static int do_clear_before(const char *str, struct expr *expr)
return 1;
if ((!expr && live_filter_expr) || (expr && !live_filter_expr))
return 1;
- if (!expr || (is_harmless_expr(str) && is_harmless_expr(lib_live_filter)))
+ if (!expr || expr_is_harmless(expr))
return !strstr(str, lib_live_filter);
return 1;
}
--
1.7.4.1
Gregory Petrosyan
2011-04-05 21:00:34 UTC
Permalink
Post by Johannes Weißl
---
expr.c | 24 ++++++++++++++++++++++++
expr.h | 2 ++
lib.c | 14 +-------------
3 files changed, 27 insertions(+), 13 deletions(-)
Merged to master, thanks!

Gregory

Loading...