diff options
author | norly <ny-git@enpas.org> | 2022-05-21 01:23:43 +0200 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2022-05-31 13:48:16 +0200 |
commit | 09f05c352b77d70d72c7e9e76e75c471a1ad0e26 (patch) | |
tree | c98f4600520f1e23b57a51190ef8806d2948de1a /module | |
parent | 850314679973283af02d1dc802c4670ca3350cdd (diff) |
Speed up can327_is_valid_rx_char() with a LUT
Diffstat (limited to 'module')
-rw-r--r-- | module/can327.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/module/can327.c b/module/can327.c index 0ff377a..aba1986 100644 --- a/module/can327.c +++ b/module/can327.c @@ -896,20 +896,30 @@ static const struct net_device_ops can327_netdev_ops = { .ndo_change_mtu = can_change_mtu, }; -static bool can327_is_valid_rx_char(char c) +static bool can327_is_valid_rx_char(u8 c) { - return (isdigit(c) || - isupper(c) || - c == ELM327_DUMMY_CHAR || - c == ELM327_READY_CHAR || - c == '<' || - c == 'a' || - c == 'b' || - c == 'v' || - c == '.' || - c == '?' || - c == '\r' || - c == ' '); + static const bool lut_char_is_valid['z'] = { + ['\r'] = true, + [' '] = true, + ['.'] = true, + ['0'] = true, true, true, true, true, + ['5'] = true, true, true, true, true, + ['<'] = true, + [ELM327_READY_CHAR] = true, + ['?'] = true, + ['A'] = true, true, true, true, true, true, true, + ['H'] = true, true, true, true, true, true, true, + ['O'] = true, true, true, true, true, true, true, + ['V'] = true, true, true, true, true, + ['a'] = true, + ['b'] = true, + ['v'] = true, + [ELM327_DUMMY_CHAR] = true, + }; + BUILD_BUG_ON(ELM327_DUMMY_CHAR >= 'z'); + + return (c < ARRAY_SIZE(lut_char_is_valid) && + lut_char_is_valid[c]); } /* Handle incoming ELM327 ASCII data. |