aboutsummaryrefslogtreecommitdiffstats
path: root/epan/packet.c
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 /epan/packet.c
parent052a2b965a424465fb87c83a5f2009b35471be8b (diff)
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
Diffstat (limited to 'epan/packet.c')
-rw-r--r--epan/packet.c19
1 files changed, 13 insertions, 6 deletions
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.
*/