getdata: new xstrstr function for performance

The strstr is changed to xstrstr, which short cuts to points in
string where first differences are expected to found. This made
the tool tiny bit quicker.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-07-11 00:08:45 +02:00
parent 8c6a3d9a4a
commit b1cd84e804
3 changed files with 32 additions and 5 deletions

View file

@ -78,6 +78,32 @@ void *safe_realloc(void *ptr, const size_t size)
return ret;
}
int
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
__attribute__ ((hot))
#endif
xstrstr(char *a, char *b, int len)
{
int i;
/* two spaces are very common in lease file, after them
* nearly everything differs */
if (a[2] != b[2]) {
return false;
}
/* " binding state " == 16 chars, this will skip right
* to first difering line. */
if (17 < len && a[17] != b[17]) {
return false;
}
/* looking good, double check the whole thing... */
for (i = 0; a[i] != '\0' && b[i] != '\0'; i++) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}
/* Simple strdup wrapper */
char *safe_strdup(const char *str)
{