diff --git a/dftest.c b/dftest.c index 05a8a1597e..9db909d997 100644 --- a/dftest.c +++ b/dftest.c @@ -165,7 +165,7 @@ main(int argc, char **argv) /* Compile it */ if (!dfilter_compile_real(expanded_text, &df, &df_err, - "dftest", TRUE, FALSE)) { + "dftest", TRUE, FALSE, FALSE)) { fprintf(stderr, "dftest: %s\n", df_err->msg); if (df_err->loc.col_start >= 0) { fprintf(stderr, "\t%s\n", expanded_text); diff --git a/epan/dfilter/dfilter-int.h b/epan/dfilter/dfilter-int.h index 7ad88f2280..3e5df9110e 100644 --- a/epan/dfilter/dfilter-int.h +++ b/epan/dfilter/dfilter-int.h @@ -55,6 +55,7 @@ typedef struct { GHashTable *references; /* hfinfo -> pointer to array of references */ GHashTable *raw_references; /* hfinfo -> pointer to array of references */ char *expanded_text; + gboolean apply_optimization; } dfwork_t; /* diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c index 9feac8e3dc..d781430119 100644 --- a/epan/dfilter/dfilter.c +++ b/epan/dfilter/dfilter.c @@ -357,7 +357,7 @@ gboolean dfilter_compile_real(const gchar *text, dfilter_t **dfp, df_error_t **errpp, const char *caller, gboolean save_tree, - gboolean apply_macros) + gboolean apply_macros, gboolean apply_optimization) { int token; dfilter_t *dfilter; @@ -393,6 +393,7 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp, } dfw = dfwork_new(); + dfw->apply_optimization = apply_optimization; if (apply_macros) { dfw->expanded_text = dfilter_macro_apply(text, &dfw->error.msg); diff --git a/epan/dfilter/dfilter.h b/epan/dfilter/dfilter.h index 0d03976364..5194e3caab 100644 --- a/epan/dfilter/dfilter.h +++ b/epan/dfilter/dfilter.h @@ -69,15 +69,16 @@ WS_DLL_PUBLIC void dfilter_error_free(df_error_t *); +// TODO: Replace booleans with a bit flag. WS_DLL_PUBLIC gboolean dfilter_compile_real(const gchar *text, dfilter_t **dfp, df_error_t **errpp, const char *caller, gboolean save_tree, - gboolean apply_macros); + gboolean apply_macros, gboolean apply_optimization); #define dfilter_compile(text, dfp, errp) \ - dfilter_compile_real(text, dfp, errp, __func__, FALSE, TRUE) + dfilter_compile_real(text, dfp, errp, __func__, FALSE, TRUE, TRUE) /* Frees all memory used by dfilter, and frees * the dfilter itself. */ diff --git a/epan/dfilter/gencode.c b/epan/dfilter/gencode.c index 8653d487bc..b223226bba 100644 --- a/epan/dfilter/gencode.c +++ b/epan/dfilter/gencode.c @@ -846,7 +846,9 @@ dfw_gencode(dfwork_t *dfw) dfw->interesting_fields = g_hash_table_new(g_int_hash, g_int_equal); gencode(dfw, dfw->st_root); dfw_append_insn(dfw, dfvm_insn_new(DFVM_RETURN)); - optimize(dfw); + if (dfw->apply_optimization) { + optimize(dfw); + } } diff --git a/tshark.c b/tshark.c index f00ba45ea1..0b4442e91b 100644 --- a/tshark.c +++ b/tshark.c @@ -626,7 +626,7 @@ _compile_dfilter(const char *text, dfilter_t **dfp, const char *caller) return FALSE; } - ok = dfilter_compile_real(expanded, dfp, &df_err, caller, FALSE, FALSE); + ok = dfilter_compile_real(expanded, dfp, &df_err, caller, FALSE, FALSE, TRUE); if (!ok ) { cmdarg_err("%s", df_err->msg);