DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH] bus: skip useless iterations in rte_bus_find
Date: Tue, 29 Aug 2017 18:19:48 +0200	[thread overview]
Message-ID: <1504023588-13085-1-git-send-email-gaetan.rivet@6wind.com> (raw)

The starting point is known. The iterator can be directly set to it.

The function rte_bus_find can easily be used with a comparison function
always returning True. This would make it a regular bus iterator.

Users doing so would however accomplish such iteration in

   O(N * N/2) = O(N^2)

Which can be avoided.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---

In practice, such cost is entirely negligible of course.
It is cleaner and more correct though.

 lib/librte_eal/common/eal_common_bus.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 9d1be8a..53bb004 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -153,15 +153,16 @@ struct rte_bus *
 rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
 	     const void *data)
 {
-	struct rte_bus *bus = NULL;
+	struct rte_bus *bus;
 
-	TAILQ_FOREACH(bus, &rte_bus_list, next) {
-		if (start && bus == start) {
-			start = NULL; /* starting point found */
-			continue;
-		}
+	if (start != NULL)
+		bus = TAILQ_NEXT(start, next);
+	else
+		bus = TAILQ_FIRST(&rte_bus_list);
+	while (bus != NULL) {
 		if (cmp(bus, data) == 0)
 			break;
+		bus = TAILQ_NEXT(bus, next);
 	}
 	return bus;
 }
-- 
2.1.4

             reply	other threads:[~2017-08-29 16:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29 16:19 Gaetan Rivet [this message]
2017-10-24  0:18 ` Ferruh Yigit
2017-10-25 11:13   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504023588-13085-1-git-send-email-gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).