aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorAndersBroman <anders.broman@ericsson.com>2016-09-22 16:18:03 +0200
committerAnders Broman <a.broman58@gmail.com>2016-09-22 15:08:58 +0000
commitf4a521ee74f01063fe2738ff5a975d5a833ab85e (patch)
tree4833378cb397667115d587f61e3211025013c21b /epan/proto.c
parent0b3d6793681fb351cd6e726d3323839cb0d86e64 (diff)
[proto.c] As we know the size of the hf array use g_ptr_array_sized_new()
to allocate the arry to hold them. This should be more efficient. Change-Id: I84b1095b6eb110fdcc1b2630949c76b51f3a47b6 Reviewed-on: https://code.wireshark.org/review/17866 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/epan/proto.c b/epan/proto.c
index fd673faf05..f4ba545002 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -5766,7 +5766,9 @@ proto_register_protocol(const char *name, const char *short_name,
protocol->name = name;
protocol->short_name = short_name;
protocol->filter_name = filter_name;
- protocol->fields = g_ptr_array_new();
+ /*protocol->fields = g_ptr_array_new();*/
+ /* Delegate until actually needed and use g_ptr_array_new_seized*/
+ protocol->fields = NULL;
protocol->is_enabled = TRUE; /* protocol is enabled by default */
protocol->enabled_by_default = TRUE; /* see previous comment */
protocol->can_toggle = TRUE;
@@ -6180,6 +6182,11 @@ proto_register_field_array(const int parent, hf_register_info *hf, const int num
int i;
proto = find_protocol_by_id(parent);
+
+ if (proto->fields == NULL) {
+ proto->fields = g_ptr_array_sized_new(num_records);
+ }
+
for (i = 0; i < num_records; i++, ptr++) {
/*
* Make sure we haven't registered this yet.
@@ -6207,7 +6214,12 @@ proto_register_fields_section(const int parent, header_field_info *hfi, const in
protocol_t *proto;
proto = find_protocol_by_id(parent);
- for (i = 0; i < num_records; i++) {
+
+ if (proto->fields == NULL) {
+ proto->fields = g_ptr_array_sized_new(num_records);
+ }
+
+ for (i = 0; i < num_records; i++) {
/*
* Make sure we haven't registered this yet.
*/
@@ -6229,6 +6241,12 @@ proto_register_fields_manual(const int parent, header_field_info **hfi, const in
protocol_t *proto;
proto = find_protocol_by_id(parent);
+
+ if (proto->fields == NULL) {
+ proto->fields = g_ptr_array_sized_new(num_records);
+ }
+
+
for (i = 0; i < num_records; i++) {
/*
* Make sure we haven't registered this yet.