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:
parent
1034321f81
commit
98612f5492
8
sdn.cpp
8
sdn.cpp
|
@ -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 {};
|
||||
|
|
Loading…
Reference in New Issue