inlined g_str_has optimisations
@bdejean
Submitted by Ben Link to original bug (#151957)
Description
gcc is able to emit optimized code for (str|strn|mem)cmp( str, "literal" )
. The current g_str_has_prefix
/ g_str_has_suffix
does not allow this. I think using
g_str_has_*( str, "literal" )
is a pretty common usage and worths this optimisation.
the following patch renames g_str_has_*
to _g_str_has_*
and defines 4 macros ( 2 to prevent multiple argument evaluation )
some benchmark results (debian gcc-3.4 -O2)
for(i = 0; i < 100000000; ++i)
{
res += g_str_has_prefix(s, "Stargate");
res += g_str_has_suffix(s, "Stargate");
res += g_str_has_prefix(s, "Super");
res += g_str_has_suffix(s, "docious");
}
PPC G4 1GHZ orig 65s -> patched 22s XP 1,666GHZ orig 37s -> patched 16s
please, consider this patch.
Edited by Emmanuele Bassi