From Kovarththanan Rajaratnam via bug 3702:

This patch optimizes the data source name processing in add_new_data_source()
by delaying it. We now simply store the constant string and lazily compute the
name when needed. This gives a performance boost because we only need the name
if we have multiple data sources.

svn path=/trunk/; revision=29066
This commit is contained in:
Stig Bjørlykke 2009-07-12 10:19:13 +00:00
parent 052a2b965a
commit 27572c22f4
7 changed files with 25 additions and 11 deletions

View File

@ -1586,7 +1586,7 @@ eventlog_dissect_element_ReadEventLogW_handle_(tvbuff_t *tvb _U_, int offset _U_
static int
eventlog_dissect_element_ReadEventLogW_flags(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)
{
offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, hf_eventlog_eventlog_ReadEventLogW_flags, 0);
offset = eventlog_dissect_bitmap_eventlogReadFlags(tvb, offset, pinfo, tree, drep, hf_eventlog_eventlog_ReadEventLogW_flags, 0);
return offset;
}

View File

@ -67,7 +67,8 @@ typedef struct _frame_data {
*/
typedef struct {
tvbuff_t *tvb;
char *name;
gboolean name_initialized;
const char *name;
} data_source;
/* Utility routines used by packet*.c */

View File

@ -485,6 +485,7 @@ get_column_title
get_column_width_string
get_datafile_dir
get_datafile_path
get_data_source_name
get_dirname
get_dissector_table_selector_type
get_dissector_table_ui_name

View File

@ -197,15 +197,22 @@ add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, const char *name)
src = ep_alloc(sizeof (data_source));
src->tvb = tvb;
/*
* XXX - if we require this argument to be a string constant,
* we don't need to allocate a buffer for a copy and make a
* copy, and wouldn't need to free the buffer, either.
*/
src->name = ep_strdup_printf("%s (%u bytes)", name, tvb_length(tvb));
src->name_initialized = FALSE;
src->name = name;
pinfo->data_src = g_slist_append(pinfo->data_src, src);
}
const char*
get_data_source_name(data_source *src)
{
if (!src->name_initialized) {
src->name = ep_strdup_printf("%s (%u bytes)", src->name, tvb_length(src->tvb));
src->name_initialized = TRUE;
}
return src->name;
}
/*
* Free up a frame's list of data sources.
*/

View File

@ -383,6 +383,11 @@ final_registration_all_protocols(void);
extern void add_new_data_source(packet_info *pinfo, tvbuff_t *tvb,
const char *name);
/*
* Return the data source name.
*/
extern const char* get_data_source_name(data_source *src);
/*
* Free up a frame's list of data sources.
*/

View File

@ -654,7 +654,7 @@ add_byte_views(epan_dissect_t *edt, GtkWidget *tree_view,
*/
for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
add_byte_tab(byte_nb_ptr, src->name, src->tvb, edt->tree,
add_byte_tab(byte_nb_ptr, get_data_source_name(src), src->tvb, edt->tree,
tree_view);
}

View File

@ -771,7 +771,7 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
GSList *src_le;
data_source *src;
tvbuff_t *tvb;
char *name;
const char *name;
char *line;
const guchar *cp;
guint length;
@ -789,7 +789,7 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
src = src_le->data;
tvb = src->tvb;
if (multiple_sources) {
name = src->name;
name = get_data_source_name(src);
print_line(stream, 0, "");
line = g_strdup_printf("%s:", name);
print_line(stream, 0, line);