diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-10-10 00:44:13 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-10-10 00:44:13 +0100 |
commit | 2ceb64261a833d8906ce2009212c1510b79026d2 (patch) | |
tree | d2b30f361fe4b577ad94199e7f2c6df96a1d99c6 | |
parent | fd769d621e95cdcf6f4600448c8431d27233c090 (diff) | |
download | termo-2ceb64261a833d8906ce2009212c1510b79026d2.tar.gz termo-2ceb64261a833d8906ce2009212c1510b79026d2.tar.xz termo-2ceb64261a833d8906ce2009212c1510b79026d2.zip |
Binary search terminfo funcname => termkey sym conversion, rather than linear
-rw-r--r-- | driver-ti.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/driver-ti.c b/driver-ti.c index 9b67c4f..44ea606 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -125,6 +125,7 @@ static struct { int mods; } funcs[] = { + /* THIS LIST MUST REMAIN SORTED! */ { "backspace", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BACKSPACE, 0 }, { "begin", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BEGIN, 0 }, { "btab", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_TAB, TERMKEY_KEYMOD_SHIFT }, @@ -147,15 +148,29 @@ static struct { static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmaskp, int *modsetp) { - int i; - for(i = 0; funcs[i].funcname; i++) { - if(strcmp(funcname, funcs[i].funcname) == 0) { + // Binary search + + int start = 0; + int end = sizeof(funcs)/sizeof(funcs[0]); // is "one past" the end of the range + + while(1) { + int i = (start+end) / 2; + int cmp = strcmp(funcname, funcs[i].funcname); + + if(cmp == 0) { *typep = funcs[i].type; *symp = funcs[i].sym; *modmaskp = funcs[i].mods; *modsetp = funcs[i].mods; return 1; } + else if(end == start + 1) + // That was our last choice and it wasn't it - not found + break; + else if(cmp > 0) + start = i; + else + end = i; } if(funcname[0] == 'f' && isdigit(funcname[1])) { |