3 ms·
Seems cleaner and possibly faster to turn the checks inside out? if (input.size() == 5) { return memcmp(input.data(), "https", 5) == 0; } if (input.s
by im3w1l 4y ago
Seems cleaner and possibly faster to turn the checks inside out?
if (input.size() == 5) {
return memcmp(input.data(), "https", 5) == 0;
}
if (input.size() == 4) {
return memcmp(input.data(), "http", 4) == 0 || memcmp(input.data(), "file", 4) == 0;
}
etc
Edit: Nvm I see the issue with this, if you have a set like
abcd1, abcd2, abcd3 then it has to try abcd first and then 1 and then abcd and then 2 and then abcd and then 3.
You could do sort of manual trie of full 8 byte chunks followed by a 4 byte step followed by a 2 byte step followed by a 1 byte step. But yeah suddenly it's not so clean anymore.
The example set doesn't have this issue though.