When regestering taps, only loop trough the list of taps once when adding

new taps.

Change-Id: Ida5ad2375c95664ee1b911d265cb69672db2be2d
Reviewed-on: https://code.wireshark.org/review/17964
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
AndersBroman 2016-09-28 12:09:58 +02:00 committed by Anders Broman
parent 152e245804
commit 148e4f77e9
1 changed files with 11 additions and 7 deletions

View File

@ -214,13 +214,19 @@ tap_init(void)
int
register_tap(const char *name)
{
tap_dissector_t *td, *tdl;
int i, tap_id;
tap_dissector_t *td, *tdl = NULL, *tdl_prev;
int i=0;
if(tap_dissector_list){
tap_id=find_tap_id(name);
if (tap_id)
return tap_id;
/* Check if we allready have the name registered, if it is return the tap_id of that tap.
* After the for loop tdl_prev will point to the last element of the list, add the new one there.
*/
for (i = 1, tdl = tap_dissector_list; tdl; i++, tdl_prev = tdl, tdl = tdl->next) {
if (!strcmp(tdl->name, name)) {
return i;
}
}
tdl = tdl_prev;
}
td=(tap_dissector_t *)g_malloc(sizeof(tap_dissector_t));
@ -231,8 +237,6 @@ register_tap(const char *name)
tap_dissector_list=td;
i=1;
} else {
for(i=2,tdl=tap_dissector_list;tdl->next;i++,tdl=tdl->next)
;
tdl->next=td;
}
return i;