epan: Rewrite an assertion on dissector handle names

Avoid an extra hash table lookup.

Requires GLib >= 2.40.
This commit is contained in:
João Valverde 2023-09-23 06:03:18 +01:00
parent b732578455
commit eeddad8f58
1 changed files with 7 additions and 4 deletions

View File

@ -3353,14 +3353,17 @@ check_valid_dissector_name_or_fail(const char *name)
static dissector_handle_t
register_dissector_handle(const char *name, dissector_handle_t handle)
{
gboolean new_entry;
/* Make sure name is "parsing friendly" - descriptions should be
* used for complicated phrases. */
check_valid_dissector_name_or_fail(name);
/* Make sure the registration is unique */
ws_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
g_hash_table_insert(registered_dissectors, (gpointer)name, handle);
new_entry = g_hash_table_insert(registered_dissectors, (gpointer)name, handle);
if (!new_entry) {
/* Make sure the registration is unique */
ws_error("dissector handle name \"%s\" is already registered", name);
}
return handle;
}