summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2018-09-01 19:00:36 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2018-09-03 09:38:36 +0100
commit20087bf22698612a526353f022bc232e2b0dcdcc (patch)
tree10167ccbaca9ea8e6dec45d1995e56e029e14108 /lib/drmtest.c
parent9e5fa9112546e5767d57237db8eace7c815b1996 (diff)
lib: Use a bsearch to find the module name
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> Reviewed-by: Katarzyna Dec <katarzyna.dec@intel.com>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 93228f90..bfb38f1e 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;
}
}