From: Gaetan Rivet Date: Tue, 29 Aug 2017 16:19:48 +0000 (+0200) Subject: bus: skip useless iterations in find function X-Git-Tag: spdx-start~1228 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=96d9dd74cde0ba14ec99c806ab25ff9b992c58d6;p=dpdk.git bus: skip useless iterations in find function 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 Reviewed-by: Ferruh Yigit --- diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index c3c77f42fd..5c63ced61e 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -146,15 +146,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; }