From Evan Huus: Clean up conversation list iterator caching. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7149

svn path=/trunk/; revision=42150
This commit is contained in:
Anders Broman 2012-04-20 05:23:41 +00:00
parent a094f232ea
commit 5007c399b9
1 changed files with 27 additions and 22 deletions

View File

@ -569,6 +569,12 @@ conversation_remove_from_hashtable(GHashTable *hashtable, conversation_t *conv)
/* Update the head of the chain */ /* Update the head of the chain */
chain_head = conv->next; chain_head = conv->next;
chain_head->last = conv->last; chain_head->last = conv->last;
if (conv->latest_found == conv)
chain_head->latest_found = NULL;
else
chain_head->latest_found = conv->latest_found;
g_hash_table_insert(hashtable, chain_head->key_ptr, chain_head); g_hash_table_insert(hashtable, chain_head->key_ptr, chain_head);
} }
} }
@ -593,6 +599,9 @@ conversation_remove_from_hashtable(GHashTable *hashtable, conversation_t *conv)
/* We're at the very end of the list. */ /* We're at the very end of the list. */
chain_head->last = prev; chain_head->last = prev;
} }
if (chain_head->latest_found == conv)
chain_head->latest_found = prev;
} }
} }
@ -728,11 +737,10 @@ static conversation_t *
conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, const address *addr1, const address *addr2, conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, const address *addr1, const address *addr2,
const port_type ptype, const guint32 port1, const guint32 port2) const port_type ptype, const guint32 port1, const guint32 port2)
{ {
conversation_t* conversation=NULL; conversation_t* convo=NULL;
conversation_t* match=NULL; conversation_t* match=NULL;
conversation_t* chain_head=NULL; conversation_t* chain_head=NULL;
conversation_key key; conversation_key key;
guint found=0;
/* /*
* We don't make a copy of the address data, we just copy the * We don't make a copy of the address data, we just copy the
@ -744,30 +752,27 @@ conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, co
key.port1 = port1; key.port1 = port1;
key.port2 = port2; key.port2 = port2;
chain_head = (match = g_hash_table_lookup(hashtable, &key)); chain_head = g_hash_table_lookup(hashtable, &key);
if (match && (match->setup_frame > frame_num))
match = NULL;
if (match) { if (chain_head && (chain_head->setup_frame <= frame_num)) {
if((match->last)&&(match->last->setup_frame<=frame_num)) match = chain_head;
return match->last;
if((match->latest_found)&&(match->latest_found->setup_frame<=frame_num)) if((chain_head->last)&&(chain_head->last->setup_frame<=frame_num))
return match->latest_found; return chain_head->last;
for (conversation = match->next; conversation; conversation = conversation->next) {
if ((conversation->setup_frame <= frame_num) if((chain_head->latest_found)&&(chain_head->latest_found->setup_frame<=frame_num))
&& (conversation->setup_frame > match->setup_frame)) { match = chain_head->latest_found;
match = conversation;
chain_head->latest_found = conversation; for (convo = match; convo && convo->setup_frame <= frame_num; convo = convo->next) {
found=1; if (convo->setup_frame > match->setup_frame) {
} else if(conversation->setup_frame>frame_num) match = convo;
/* we are past the frame_num */ }
break;
} }
if(!found)
match=NULL;
} }
if (match)
chain_head->latest_found = match;
return match; return match;
} }