aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-10-15 16:56:31 +0100
committerJoão Valverde <j@v6e.pt>2021-10-15 17:04:32 +0100
commit6d4a4636206c4c0506466177cba1b5f04fa73e09 (patch)
tree926970a91f2a43c9e6f920b4d7a7b587ec64b986
parent07023a7774dd2a6d8716df1bdab780e8bfc2999f (diff)
proto: use hash table to lookup reserved filter names
Should be faster.
-rw-r--r--epan/proto.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/epan/proto.c b/epan/proto.c
index 9a3f412cb7..8b906dd44c 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -444,6 +444,26 @@ static GHashTable* proto_names = NULL;
static GHashTable* proto_short_names = NULL;
static GHashTable* proto_filter_names = NULL;
+static const char *reserved_filter_names[] = {
+ /* Display filter keywords. */
+ "eq",
+ "ne",
+ "gt",
+ "ge",
+ "lt",
+ "le",
+ "bitwise_and",
+ "contains",
+ "matches",
+ "not",
+ "and",
+ "or",
+ "in",
+ NULL
+};
+
+static GHashTable *proto_reserved_filter_names = NULL;
+
static gint
proto_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
{
@@ -502,6 +522,12 @@ proto_init(GSList *register_all_plugin_protocols_list,
proto_short_names = g_hash_table_new(g_str_hash, g_str_equal);
proto_filter_names = g_hash_table_new(g_str_hash, g_str_equal);
+ proto_reserved_filter_names = g_hash_table_new(g_str_hash, NULL);
+ for (const char **ptr = reserved_filter_names; *ptr != NULL; ptr++) {
+ /* GHashTable has no key destructor. */
+ g_hash_table_add(proto_reserved_filter_names, *(char **)ptr);
+ }
+
gpa_hfinfo.len = 0;
gpa_hfinfo.allocated_len = 0;
gpa_hfinfo.hfi = NULL;
@@ -621,6 +647,11 @@ proto_cleanup_base(void)
proto_filter_names = NULL;
}
+ if (proto_reserved_filter_names) {
+ g_hash_table_destroy(proto_reserved_filter_names);
+ proto_reserved_filter_names = NULL;
+ }
+
if (gpa_hfinfo.allocated_len) {
gpa_hfinfo.len = 0;
gpa_hfinfo.allocated_len = 0;
@@ -7349,29 +7380,10 @@ check_valid_filter_name_or_fail(const char *filter_name)
" This might be caused by an inappropriate plugin or a development error.", filter_name);
}
- const char *reserved_filter_names[] = {
- /* Display filter keywords. */
- "eq",
- "ne",
- "gt",
- "ge",
- "lt",
- "le",
- "bitwise_and",
- "contains",
- "matches",
- "not",
- "and",
- "or",
- "in",
- NULL
- };
-
/* Check for reserved keywords. */
- for (const char **ptr = reserved_filter_names; *ptr != NULL; ptr++) {
- if (strcmp(*ptr, filter_name) == 0) {
- ws_error("Protocol filter name \"%s\" is a reserved keyword.", filter_name);
- }
+ if (g_hash_table_contains(proto_reserved_filter_names, filter_name)) {
+ ws_error("Protocol filter name \"%s\" is invalid because it is a reserved keyword."
+ " This might be caused by an inappropriate plugin or a development error.", filter_name);
}
}