summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2009-07-12 10:19:13 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2009-07-12 10:19:13 +0000
commit27572c22f4c47b845c90700f46e27d239515531c (patch)
tree8a20bb03d20a569e22078dd31657e0eaa9bd66e3
parent052a2b965a424465fb87c83a5f2009b35471be8b (diff)
downloadwireshark-27572c22f4c47b845c90700f46e27d239515531c.tar.gz
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
-rw-r--r--epan/dissectors/packet-dcerpc-eventlog.c2
-rw-r--r--epan/frame_data.h3
-rw-r--r--epan/libwireshark.def1
-rw-r--r--epan/packet.c19
-rw-r--r--epan/packet.h5
-rw-r--r--gtk/main_proto_draw.c2
-rw-r--r--print.c4
7 files changed, 25 insertions, 11 deletions
diff --git a/epan/dissectors/packet-dcerpc-eventlog.c b/epan/dissectors/packet-dcerpc-eventlog.c
index 817b32e3d5..0a14d24258 100644
--- a/epan/dissectors/packet-dcerpc-eventlog.c
+++ b/epan/dissectors/packet-dcerpc-eventlog.c
@@ -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;
}
diff --git a/epan/frame_data.h b/epan/frame_data.h
index f8332803e9..197cf332bf 100644
--- a/epan/frame_data.h
+++ b/epan/frame_data.h
@@ -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 */
diff --git a/epan/libwireshark.def b/epan/libwireshark.def
index f3456b8088..462350bf28 100644
--- a/epan/libwireshark.def
+++ b/epan/libwireshark.def
@@ -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
diff --git a/epan/packet.c b/epan/packet.c
index 56742448d9..39eefb0b07 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -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.
*/
diff --git a/epan/packet.h b/epan/packet.h
index 9f35f4d234..5725b58dd5 100644
--- a/epan/packet.h
+++ b/epan/packet.h
@@ -384,6 +384,11 @@ 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.
*/
extern void free_data_sources(packet_info *pinfo);
diff --git a/gtk/main_proto_draw.c b/gtk/main_proto_draw.c
index 4a0b3d9d46..9451123456 100644
--- a/gtk/main_proto_draw.c
+++ b/gtk/main_proto_draw.c
@@ -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);
}
diff --git a/print.c b/print.c
index 580ba1ff88..d9178a842d 100644
--- a/print.c
+++ b/print.c
@@ -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);