[PATCH v3 02/13] match_pathname: avoid calling strncmp if baselen is 0
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- Mar 12, 2013, 13:04 UTC
- Message-ID
- <1363093500-16796-3-git-send-email-pclouds@gmail.com>
- In-Reply-To
- <1363093500-16796-1-git-send-email-pclouds@gmail.com>
This reduces "git status" user time by a little bit. This is the sorted results of 10 consecutive runs of "git ls-files --exclude-standard -o" on webkit.git, compiled with gcc -O2:
treat_leading_path: 0.000 0.000 read_directory: 4.102 3.674 +treat_one_path: 2.843 2.427 ++is_excluded: 2.632 2.221 +++prep_exclude: 0.225 0.224 +++matching: 2.054 1.650 ++dir_exist: 0.035 0.035 ++index_name_exists: 0.292 0.288 lazy_init_name_hash: 0.258 0.257 +simplify_away: 0.085 0.085 +dir_add_name: 0.446 0.441
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dir.c b/dir.c index 69c045b..32a3adb 100644 --- a/dir.c +++ b/dir.c @@ -688,8 +688,8 @@ int match_pathname(const char *pathname, int pathlen, * may not end with a trailing slash though. */ if (pathlen < baselen + 1 || - (baselen && pathname[baselen] != '/') || - strncmp_icase(pathname, base, baselen)) + (baselen && (pathname[baselen] != '/' || + strncmp_icase(pathname, base, baselen)))) return 0; namelen = baselen ? pathlen - baselen - 1 : pathlen;
-- 1.8.1.2.536.gf441e6d