All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] lib: Use a bsearch to find the module name
@ 2018-09-01 18:09 Chris Wilson
  2018-09-01 18:46 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Chris Wilson @ 2018-09-01 18:09 UTC (permalink / raw)
  To: igt-dev

Even with a small number of known drivers (6), a bsearch will take at
most 3 steps, whereas the linear search will take 3 steps on average. In
the future with more known drivers, the logN bsearch will be even more
advantageous.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Katarzyna Dec <katarzyna.dec@intel.com>
---
 lib/drmtest.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 93228f900..bfb38f1e9 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -222,9 +222,15 @@ static int open_device(const char *name, unsigned int chipset)
 	if (__get_drm_device_name(fd, dev_name, sizeof(dev_name) - 1) == -1)
 		goto err;
 
-	for (const struct module *m = modules; m->module; m++) {
-		if (strcmp(m->module, dev_name) == 0) {
-			chip = m->bit;
+	for (int start = 0, end = ARRAY_SIZE(modules) - 1; start < end; ){
+		int mid = start + (end - start) / 2;
+		int ret = strcmp(modules[mid].module, dev_name);
+		if (ret < 0) {
+			end = mid;
+		} else if (ret > 0) {
+			start = mid + 1;
+		} else {
+			chip = modules[mid].bit;
 			break;
 		}
 	}
-- 
2.19.0.rc1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-09-03 14:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-01 18:09 [igt-dev] [PATCH i-g-t] lib: Use a bsearch to find the module name Chris Wilson
2018-09-01 18:46 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-09-01 19:35 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-09-03  7:02 ` [igt-dev] [PATCH i-g-t] " Katarzyna Dec
2018-09-03  9:39 ` Petri Latvala
2018-09-03  9:44   ` Chris Wilson
2018-09-03 10:34     ` Jani Nikula
2018-09-03 10:39       ` Chris Wilson
2018-09-03 11:01 ` [igt-dev] ✓ Fi.CI.BAT: success for lib: Use a bsearch to find the module name (rev2) Patchwork
2018-09-03 14:43 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.