[1/2] lpm: remove unnecessary temporary VLA

Message ID 20240507025355.7145-1-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series [1/2] lpm: remove unnecessary temporary VLA |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger May 7, 2024, 2:53 a.m. UTC
  Do not need to recompute all the table indices.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/lpm/rte_lpm.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Comments

Bruce Richardson May 7, 2024, 7:51 a.m. UTC | #1
On Mon, May 06, 2024 at 07:53:54PM -0700, Stephen Hemminger wrote:
> Do not need to recompute all the table indices.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h
index 2888e5f4ca..9c6df311cb 100644
--- a/lib/lpm/rte_lpm.h
+++ b/lib/lpm/rte_lpm.h
@@ -337,7 +337,6 @@  rte_lpm_lookup_bulk_func(const struct rte_lpm *lpm, const uint32_t *ips,
 		uint32_t *next_hops, const unsigned n)
 {
 	unsigned i;
-	unsigned tbl24_indexes[n];
 	const uint32_t *ptbl;
 
 	/* DEBUG: Check user input arguments. */
@@ -345,12 +344,10 @@  rte_lpm_lookup_bulk_func(const struct rte_lpm *lpm, const uint32_t *ips,
 			(next_hops == NULL)), -EINVAL);
 
 	for (i = 0; i < n; i++) {
-		tbl24_indexes[i] = ips[i] >> 8;
-	}
+		unsigned int tbl24_index = ips[i] >> 8;
 
-	for (i = 0; i < n; i++) {
 		/* Simply copy tbl24 entry to output */
-		ptbl = (const uint32_t *)&lpm->tbl24[tbl24_indexes[i]];
+		ptbl = (const uint32_t *)&lpm->tbl24[tbl24_index];
 		next_hops[i] = *ptbl;
 
 		/* Overwrite output with tbl8 entry if needed */