'find ./ -name *.jpg'
I am trying to optimize 'find' command for the above statement.
method which handle the '-name' predicate in find implementation.
static boolean
pred__name __common (const char *pathname, const char *str, int flags)
{
boolean b;
char *base = base_name (pathname);
strip__trailing __slashes(base);
b = fnmatch (str, base, flags) == 0;
free (base);
return b;
}
since I am looking for file extensions and want to avoid the regular expression based string matching, I replaced 'b = fnmatch (str, base, flags) == 0;' with following statements
int strLen = strlen(base);
b = FNM_NOMATCH;
if (strLen>=4 && (str[3] == base[strLen]) &&
(str[2] == base[strLen -1]) && (str[1] ==
base[strLen-2]) && (str[0] == base[strLen-3]))
{
b = 0;
}
After this I expected some performance gain, but I don't see any kind of performance gain after the above change.
- Is that I am doing some thing wrong?
- is there a better way to optimize the 'find' to search only for file extensions?