I have a critical section of code which examines each char in many strings to ensure it falls in an acceptable range.
Is there any way i can perform such filtering without branching?
...
int i, c;
int sl = strnlen(s, 1023);
for( i = 0; i < sl; i++ ) {
c = s[i];
if( c < 68 || c > 88 )
return E_INVALID;
}
if( 0 == i )
return E_INVALID;
... do something with s ...
I was thinking some kind of filtering using bitwise operations might be possible, but in practice i can't see how to make this work. Bitwise AND with 95 trims the range down to 0-31,64-95. i can't see how to progress without introducing an if test, rendering the idea of skipping the branching void.