Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> writes: > strncmp is provided length information which could be taken advantage > by the underlying implementation. I may be missing something fundamental, but I somehow find the above does not make any sense. strcmp(a, b) has to pay attention to NUL in these strings and stop comparison. strncmp(a, b, n) not only has to pay the same attention to NUL in the strings, but also needs to stop comparing at n bytes. In what situation can the latter take advantage of that extra thing that it needs to keep track of and operate faster, when n is the length of shorter of the two strings? > diff --git a/dir.c b/dir.c > index 9960a37..46b24db 100644 > --- a/dir.c > +++ b/dir.c > @@ -610,12 +610,14 @@ int match_basename(const char *basename, int basenamelen, > int flags) > { > if (prefix == patternlen) { > - if (!strcmp_icase(pattern, basename)) > + if (patternlen == basenamelen && > + !strncmp_icase(pattern, basename, patternlen)) > return 1; What happens if you replace this with if (patternlen == baselen && !strcmp_icase(pattern, basename, patternlen)) and drop the other hunk and run the benchmark again? > } else if (flags & EXC_FLAG_ENDSWITH) { > if (patternlen - 1 <= basenamelen && > - !strcmp_icase(pattern + 1, > - basename + basenamelen - patternlen + 1)) > + !strncmp_icase(pattern + 1, > + basename + basenamelen - patternlen + 1, > + patternlen - 1)) > return 1; > } else { > if (fnmatch_icase(pattern, basename, 0) == 0) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html