On 21/11/2025 18:41, Michael Sanders wrote:Try that with AVX. Make a 256 bit vector with 0's and a vector with '9's.
So strspn, perfect for what I need!
before:
int ok = 1;
if (strlen(colorSpec) == 4) {
for (int i = 0; i < 4; i++) {
char c = colorSpec[i];
if (c < '1' || c > '8') { ok = 0; break; }
}
} else ok = 0;
after:
strspn() returns the length of the leading substring
consisting ONLY of characters in the allowed set...
if (strlen(colorSpec) != 4 && strspn(colorSpec, "12345678") = 4) FAIL;
Performance probably isn't critical in your use-case, but the solution
using 'strspn' was three times as slow as doing the explicit code.
(Test string was a fixed "8725" and tested 100M times.)
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,090 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 45:21:32 |
| Calls: | 13,946 |
| Calls today: | 3 |
| Files: | 187,034 |
| D/L today: |
8,062 files (2,942M bytes) |
| Messages: | 2,460,945 |