diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 19:41:47 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 19:41:47 +0300 |
| commit | 1b52f704a005d79d00b1260b1e5bc5d6798ff7b6 (patch) | |
| tree | 798c93f1007d0156635d9db63d47ae9a6328dd80 /src/escape.c | |
| parent | 01e1c61e9fcf4a0b0164a7fe5395a209a50f6905 (diff) | |
Replace scalar loops with SIMD spans, packed stores, and direct wrap-pad checks
Diffstat (limited to 'src/escape.c')
| -rw-r--r-- | src/escape.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/escape.c b/src/escape.c index 1e56d77..7956017 100644 --- a/src/escape.c +++ b/src/escape.c @@ -76,7 +76,16 @@ static int dcs_decode_hex(const char *s, int len, char *out, int cap) { if (len & 1) return -1; int n = 0; - for (int i = 0; i < len; i += 2) { + int i = 0; + for (; i + 4 <= len; i += 4) { + int h0 = hex_val[(unsigned char)s[i]], l0 = hex_val[(unsigned char)s[i + 1]]; + int h1 = hex_val[(unsigned char)s[i + 2]], l1 = hex_val[(unsigned char)s[i + 3]]; + if ((h0 | l0 | h1 | l1) < 0 || n + 2 > cap) return -1; + out[n] = (char)(h0 << 4 | l0); + out[n + 1] = (char)(h1 << 4 | l1); + n += 2; + } + if (i < len) { int hi = hex_val[(unsigned char)s[i]], lo = hex_val[(unsigned char)s[i + 1]]; if ((hi | lo) < 0 || n >= cap) return -1; out[n++] = (char)(hi << 4 | lo); |
