diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 19:22:05 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 19:22:05 +0300 |
| commit | 01e1c61e9fcf4a0b0164a7fe5395a209a50f6905 (patch) | |
| tree | 1f1eb33e49eab338650a42e8f602af75d8d28a24 /src/osc/clipboard.c | |
| parent | 2d02d39d2cd32e9eb559638865d2746f02c08556 (diff) | |
Optimize hot loops with direct access, LUTs, and closed-form formulas
Diffstat (limited to 'src/osc/clipboard.c')
| -rw-r--r-- | src/osc/clipboard.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/osc/clipboard.c b/src/osc/clipboard.c index a5ac59d..4f550ba 100644 --- a/src/osc/clipboard.c +++ b/src/osc/clipboard.c @@ -3,21 +3,36 @@ #include <stdlib.h> #include <string.h> -static int b64_val(char c) +static const int8_t b64_lut[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; + +static inline int b64_val(char c) { - if (c >= 'A' && c <= 'Z') return c - 'A'; - if (c >= 'a' && c <= 'z') return c - 'a' + 26; - if (c >= '0' && c <= '9') return c - '0' + 52; - if (c == '+') return 62; - if (c == '/') return 63; - return -1; + return b64_lut[(unsigned char)c]; } static bool b64_decode(const char *s, size_t n, char *out, size_t *out_len) { size_t pad = 0; - while (pad < n && s[n - pad - 1] == '=') - pad++; + if (n > 0 && s[n - 1] == '=') { + pad = (n > 1 && s[n - 2] == '=') ? ((n > 2 && s[n - 3] == '=') ? 3 : 2) : 1; + } n -= pad; if (pad > 2 || (pad && n % 4 + pad != 4)) return false; |
