From 5654dfd982ea3b790368630afb8b0af4eba2e30c Mon Sep 17 00:00:00 2001 From: Phan Duc Nhat Minh Date: Thu, 25 Jun 2020 11:30:22 +0800 Subject: Optimize heuristic search by bubbling the matched element The matched entry is bubbled to the head of the list for faster future search. Change-Id: I47375515f43387adbe0652556c03f0979a8dbe85 Reviewed-on: https://code.wireshark.org/review/37395 Petri-Dish: Martin Mathieson Tested-by: Petri Dish Buildbot Reviewed-by: Martin Mathieson --- epan/packet.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'epan/packet.c') diff --git a/epan/packet.c b/epan/packet.c index be85cbb3b8..aeb55aa377 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -2752,6 +2752,7 @@ dissector_try_heuristic(heur_dissector_list_t sub_dissectors, tvbuff_t *tvb, const char *saved_curr_proto; const char *saved_heur_list_name; GSList *entry; + GSList *prev_entry = NULL; guint16 saved_can_desegment; guint saved_layers_len = 0; heur_dtbl_entry_t *hdtbl_entry; @@ -2835,9 +2836,17 @@ dissector_try_heuristic(heur_dissector_list_t sub_dissectors, tvbuff_t *tvb, } if (len) { *heur_dtbl_entry = hdtbl_entry; + + /* Bubble the matched entry to the top for faster search next time. */ + if (prev_entry != NULL) { + prev_entry = g_slist_remove_link(prev_entry, entry); + sub_dissectors->dissectors = g_slist_concat(entry, sub_dissectors->dissectors); + } + status = TRUE; break; } + prev_entry = entry; } pinfo->current_proto = saved_curr_proto; -- cgit v1.2.3