Improve C-char parsing

I was hoping that a superoptimiser would help me find a miraculous
branchless equation to cover it, but in the end the branching
doesn't hurt at all in our case.

It's more readable than `(((char >> 2) - 0x38) & 0x60) ^ char`
or `(char ^ 0x40) & (((char >> 1) ^ 0x20) | 0x5f)`.
This commit is contained in:
Přemysl Eric Janouch 2021-07-09 04:36:43 +02:00
parent 1034321f81
commit 98612f5492
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 4 additions and 4 deletions

View File

@ -398,9 +398,9 @@ fun decode_attrs (const vector<string> &attrs) -> chtype {
// --- Application -------------------------------------------------------------
enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
#define KEY(name) (SYM | KEY_ ## name)
#define CTRL(char) ((char - 64) & 0x7f) // 60..7f aren't translated correctly
#define CTRL(char) ((char) == '?' ? 0x7f : (char) & 0x1f)
#define ACTIONS(XX) XX(NONE) XX(HELP) XX(QUIT) XX(QUIT_NO_CHDIR) \
XX(CHOOSE) XX(CHOOSE_FULL) XX(VIEW) XX(EDIT) XX(SORT_LEFT) XX(SORT_RIGHT) \
@ -1571,11 +1571,11 @@ fun parse_key (const string &key_name) -> wint_t {
return c | g.name_to_key.at (p);
} else if (!strncmp (p, "C-", 2)) {
p += 2;
if (*p < '?' || *p > 'z') {
if (*p < '?' || *p > '~') {
cerr << "bindings: invalid combination: " << key_name << endl;
return WEOF;
}
c |= CTRL (toupper (*p));
c |= CTRL (*p);
p += 1;
} else {
wchar_t w; mbstate_t mb {};