Subject: | Long spans of == tests could be replaced by strcmp |
The perl core uses this module to generate keyword parsing. There are
cases where there are long strings of, for example,
if (name[0] == 'g' &&
name[1] == 'e' &&
name[2] == 't' &&
name[3] == 'p' &&
name[4] == 'r' &&
name[5] == 'o' &&
name[6] == 't' &&
name[7] == 'o' &&
name[8] == 'b' &&
name[9] == 'y' &&
name[10] == 'n' &&
name[11] == 'a' &&
name[12] == 'm' &&
name[13] == 'e')
These could be replaced by a strcmp(name, "getprotobyname"). (Actually
in perl, it would be a call to the macro memEQ instead, which resolves
to an appropriate function on the target hardware.
I propose that this module be enhanced to generate those things, with
the constructor taking arguments as to the function to call, and the
number of consecutive tests needed to change to use the function. I
don't know what the default should be. It would depend on the
particular platform, and its caching characteristics