Ethereal-dev: [Ethereal-dev] Another small peformance optimization - packet-ip.c

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Yaniv Kaul <ykaul@xxxxxxxxxxxx>
Date: Sat, 29 Jan 2005 22:59:54 +0200
Attached please find a small performance optimization to packet-ip.c, which removes multiple redundant calls to tvb_get_ptr().

Also, I'd be happy if my previous patch (http://www.ethereal.com/lists/ethereal-dev/200501/msg00510.html) can be examined and accepted if found appropriate.

Regards,
Y.
Index: epan/dissectors/packet-ip.c
===================================================================
--- epan/dissectors/packet-ip.c	(revision 13196)
+++ epan/dissectors/packet-ip.c	(working copy)
@@ -831,6 +831,7 @@
   static e_ip eip_arr[4];
   static int eip_current=0;
   e_ip *iph;
+  const char		*src_addr, *dst_addr;
 
   eip_current++;
   if(eip_current==4){
@@ -974,10 +975,10 @@
     if (tree)
       proto_tree_add_uint(ip_tree, hf_ip_checksum, tvb, offset + 10, 2, iph->ip_sum);
   }
-
-  SET_ADDRESS(&pinfo->net_src, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_SRC, 4));
-  SET_ADDRESS(&pinfo->src, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_SRC, 4));
-  SET_ADDRESS(&iph->ip_src, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_SRC, 4));
+  src_addr = tvb_get_ptr(tvb, offset + IPH_SRC, 4);
+  SET_ADDRESS(&pinfo->net_src, AT_IPv4, 4, src_addr);
+  SET_ADDRESS(&pinfo->src, AT_IPv4, 4, src_addr);
+  SET_ADDRESS(&iph->ip_src, AT_IPv4, 4, src_addr);
   if (tree) {
     memcpy(&addr, iph->ip_src.data, 4);
     if (ip_summary_in_tree) {
@@ -987,11 +988,11 @@
     proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, addr);
     proto_tree_add_ipv4_hidden(ip_tree, hf_ip_addr, tvb, offset + 12, 4, addr);
   }
+  dst_addr = tvb_get_ptr(tvb, offset + IPH_DST, 4);
+  SET_ADDRESS(&pinfo->net_dst, AT_IPv4, 4, dst_addr);
+  SET_ADDRESS(&pinfo->dst, AT_IPv4, 4, dst_addr);
+  SET_ADDRESS(&iph->ip_dst, AT_IPv4, 4, dst_addr);
 
-  SET_ADDRESS(&pinfo->net_dst, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_DST, 4));
-  SET_ADDRESS(&pinfo->dst, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_DST, 4));
-  SET_ADDRESS(&iph->ip_dst, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_DST, 4));
-
   if (tree) {
     memcpy(&addr, iph->ip_dst.data, 4);
     if (ip_summary_in_tree) {