[dpdk-dev,v2,1/6] ixgbe: put only non-zero initializer in definition

Message ID 1409240559-14447-2-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Bruce Richardson Aug. 28, 2014, 3:42 p.m. UTC
  Since all unspecified fields in an initializer are assumed to be zero we
can simplify the empty mbuf definition in the vector driver to only use
the fields that are non-zero, i.e. just nb_segs = 1. This makes things
shorter and means that the structure doesn't need as many updates for
other fields being renamed or moved.

The variable itself is never modified and only used by a single function
so it can be made const and local to the using function.

Changes in v2:
* None

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 29 +++++------------------------
 1 file changed, 5 insertions(+), 24 deletions(-)
  

Comments

De Lara Guarch, Pablo Sept. 5, 2014, 4:14 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> Sent: Thursday, August 28, 2014 4:43 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v2 1/6] ixgbe: put only non-zero initializer in
> definition
> 
> Since all unspecified fields in an initializer are assumed to be zero we
> can simplify the empty mbuf definition in the vector driver to only use
> the fields that are non-zero, i.e. just nb_segs = 1. This makes things
> shorter and means that the structure doesn't need as many updates for
> other fields being renamed or moved.
> 
> The variable itself is never modified and only used by a single function
> so it can be made const and local to the using function.
> 
> Changes in v2:
> * None
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Acked-by Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
Olivier Matz Sept. 8, 2014, 7:55 a.m. UTC | #2
Hello Bruce,

On 08/28/2014 05:42 PM, Bruce Richardson wrote:
> Since all unspecified fields in an initializer are assumed to be zero we
> can simplify the empty mbuf definition in the vector driver to only use
> the fields that are non-zero, i.e. just nb_segs = 1. This makes things
> shorter and means that the structure doesn't need as many updates for
> other fields being renamed or moved.
> 
> The variable itself is never modified and only used by a single function
> so it can be made const and local to the using function.
> 
> Changes in v2:
> * None
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>
  

Patch

diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
index 92e07de..56dce23 100644
--- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
+++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
@@ -44,33 +44,14 @@ 
 #pragma GCC diagnostic ignored "-Wcast-qual"
 #endif
 
-static struct rte_mbuf mb_def = {
-
-	.ol_flags = 0,
-	{
-		.pkt = {
-			.data_len = 0,
-			.pkt_len = 0,
-
-			.vlan_macip = {
-				.data = 0,
-			},
-			.hash = {
-				.rss = 0,
-			},
-
-			.nb_segs = 1,
-			.in_port = 0,
-
-			.next = NULL,
-			.data = NULL,
-		},
-	},
-};
-
 static inline void
 ixgbe_rxq_rearm(struct igb_rx_queue *rxq)
 {
+	static const struct rte_mbuf mb_def = {
+		.pkt = {
+			.nb_segs = 1,
+		},
+	};
 	int i;
 	uint16_t rx_id;
 	volatile union ixgbe_adv_rx_desc *rxdp;