]> git.ipfire.org Git - thirdparty/git.git/commit
match_pathname(): reorder prefix-match check
authorJeff King <peff@peff.net>
Sun, 26 Oct 2025 15:41:46 +0000 (11:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Oct 2025 23:30:39 +0000 (16:30 -0700)
commit9d6c580d01800defbd9497dbe6a694dc31179dce
treeaac1a2bc8e85dedb213abaae0dbdbcb1f0a5d9f1
parentc44beea485f0f2feaf460e2ac87fdd5608d63cf0
match_pathname(): reorder prefix-match check

As an optimization, we use fspathncmp() to match a prefix of the pattern
that does not contain any wildcards, and then pass the remainder to
fnmatch(). If it has matched the whole thing, we can return early.

Let's shift this early-return check to before we tweak the pattern and
name strings. That will gives us more flexibility with that tweaking.

It might also save a few instructions, but I couldn't measure any
improvement in doing so (and I wouldn't be surprised if an optimizing
compiler could figure that out itself).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c