From c6d4c8037191abc1ec2bd54003f363d43e0fa5c4 Mon Sep 17 00:00:00 2001 From: Anders Broman Date: Tue, 8 Sep 2009 10:33:15 +0000 Subject: From : Didier Gautheron speed up a little proto_custom_set. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3972 svn path=/trunk/; revision=29789 --- epan/column-utils.c | 14 ++++++++++++-- epan/column_info.h | 1 + epan/epan.c | 4 ++-- epan/epan.h | 2 +- epan/proto.c | 10 +++------- epan/proto.h | 4 ++-- 6 files changed, 21 insertions(+), 14 deletions(-) (limited to 'epan') diff --git a/epan/column-utils.c b/epan/column-utils.c index 9b40a9a0d7..f8f5238449 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -59,6 +59,7 @@ col_setup(column_info *cinfo, gint num_cols) cinfo->col_last = g_new(int, NUM_COL_FMTS); cinfo->col_title = g_new(gchar*, num_cols); cinfo->col_custom_field = g_new(gchar*, num_cols); + cinfo->col_custom_field_id = g_new(int, num_cols); cinfo->col_custom_dfilter = g_new(dfilter_t*, num_cols); cinfo->col_data = (const gchar **)g_new(gchar*, num_cols); cinfo->col_buf = g_new(gchar*, num_cols); @@ -296,7 +297,7 @@ void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo) if (cinfo->fmt_matx[i][COL_CUSTOM] && cinfo->col_custom_field[i]) { cinfo->col_data[i] = cinfo->col_buf[i]; - cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field[i], + cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field_id[i], cinfo->col_buf[i], cinfo->col_expr.col_expr_val[i], COL_MAX_LEN); @@ -314,9 +315,18 @@ col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo) for (i = cinfo->col_first[COL_CUSTOM]; i <= cinfo->col_last[COL_CUSTOM]; i++) { + + cinfo->col_custom_field_id[i] = -1; if (cinfo->fmt_matx[i][COL_CUSTOM] && - cinfo->col_custom_dfilter[i]) + cinfo->col_custom_dfilter[i]){ epan_dissect_prime_dfilter(edt, cinfo->col_custom_dfilter[i]); + if (cinfo->col_custom_field) { + header_field_info* hfinfo = proto_registrar_get_byname(cinfo->col_custom_field[i]); + /* ASSERT if none ? */ + g_assert(hfinfo); + cinfo->col_custom_field_id[i] = hfinfo->id; + } + } } } diff --git a/epan/column_info.h b/epan/column_info.h index f5c796e9f5..8984cddd4a 100644 --- a/epan/column_info.h +++ b/epan/column_info.h @@ -47,6 +47,7 @@ typedef struct _column_info { gint *col_last; /* Last column number with a given format */ gchar **col_title; /* Column titles */ gchar **col_custom_field; /* Custom column field */ + gint *col_custom_field_id; /* Custom column field id*/ struct _dfilter_t **col_custom_dfilter; /* Compiled custom column field */ const gchar **col_data; /* Column data */ gchar **col_buf; /* Buffer into which to copy data for column */ diff --git a/epan/epan.c b/epan/epan.c index 048695b51a..b4d64a3dd1 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -231,11 +231,11 @@ epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode) /* ----------------------- */ const gchar * -epan_custom_set(epan_dissect_t *edt, const gchar *field, +epan_custom_set(epan_dissect_t *edt, int field_id, gchar *result, gchar *expr, int size ) { - return proto_custom_set(edt->tree, field, result, expr, size); + return proto_custom_set(edt->tree, field_id, result, expr, size); } void diff --git a/epan/epan.h b/epan/epan.h index 759d0fbd6f..82391b146d 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -123,7 +123,7 @@ epan_dissect_free(epan_dissect_t* edt); /* Sets custom column */ const gchar * -epan_custom_set(epan_dissect_t *edt, const gchar *field, +epan_custom_set(epan_dissect_t *edt, int id, gchar *result, gchar *expr, int size ); #endif /* EPAN_H */ diff --git a/epan/proto.c b/epan/proto.c index e13696ae13..d26a105638 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -3276,7 +3276,7 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap) /* -------------------------- */ const gchar * -proto_custom_set(proto_tree* tree, const gchar *field, +proto_custom_set(proto_tree* tree, int field_id, gchar *result, gchar *expr, int size ) { @@ -3292,13 +3292,9 @@ proto_custom_set(proto_tree* tree, const gchar *field, field_info *finfo; header_field_info* hfinfo; - if (!field) - return ""; + g_assert(field_id>=0); - /* speed up by storing field id in column info ? they - are already in the filter. - */ - hfinfo = g_tree_lookup(gpa_name_tree, field); + hfinfo = proto_registrar_get_nth((guint)field_id); /* do we need to rewind ? */ if (!hfinfo) diff --git a/epan/proto.h b/epan/proto.h index 95848cb0b3..4c4c8cfbf2 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -1646,12 +1646,12 @@ proto_check_field_name(const gchar *field_name); /** Check if given string is a valid field name - @param field the field name used for custom column + @param field_id the field id used for custom column @param result the buffer to fill with the field string @param expr the filter expression @param aize the size of the string buffer */ const gchar * -proto_custom_set(proto_tree* tree, const gchar *field, +proto_custom_set(proto_tree* tree, int field_id, gchar *result, gchar *expr, int size ); -- cgit v1.2.3