From 6de96915c0b12870e0cf2204fd060fb0735da728 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 8 Sep 2011 21:02:45 -0500 Subject: tree-walk: drop unused parameter from match_dir_prefix Signed-off-by: Dan McGee Signed-off-by: Junio C Hamano --- tree-walk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tree-walk.c') diff --git a/tree-walk.c b/tree-walk.c index 322becc3b..9be800760 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -522,7 +522,7 @@ static int match_entry(const struct name_entry *entry, int pathlen, return 0; } -static int match_dir_prefix(const char *base, int baselen, +static int match_dir_prefix(const char *base, const char *match, int matchlen) { if (strncmp(base, match, matchlen)) @@ -579,7 +579,7 @@ int tree_entry_interesting(const struct name_entry *entry, if (baselen >= matchlen) { /* If it doesn't match, move along... */ - if (!match_dir_prefix(base_str, baselen, match, matchlen)) + if (!match_dir_prefix(base_str, match, matchlen)) goto match_wildcards; if (!ps->recursive || ps->max_depth == -1) -- cgit v1.2.1 From 1b74092373898a53885cfb7e89aa54f9329a92d3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 8 Sep 2011 21:02:46 -0500 Subject: tree-walk: micro-optimization in tree_entry_interesting In the case of a wide breadth top-level tree (~2400 entries, all trees in this case), we can see a noticeable cost in the profiler calling strncmp() here. Most of the time we are at the base level of the repository, so base is "" and baselen == 0, which means we will always test true. Break out this one tiny case so we can short circuit the strncmp() call. Test cases are as follows. packages.git is the Arch Linux git-svn clone of the packages repository which has the characteristics above. Commands: [1] packages.git, /usr/bin/time git log >/dev/null [2] packages.git, /usr/bin/time git log -- autogen/trunk pacman/trunk wget/trunk >/dev/null [3] linux.git, /usr/bin/time git log >/dev/null [4] linux.git, /usr/bin/time git log -- drivers/ata drivers/uio tools >/dev/null Results: before after %faster [1] 2.56 2.55 0.4% [2] 51.82 48.66 6.5% [3] 5.58 5.61 -0.5% [4] 1.55 1.51 0.2% The takeaway here is this doesn't matter in many operations, but it does for a certain style of repository and operation where it nets a 6.5% measured improvement. The other changes are likely not significant by reasonable statistics methods. Note: the measured improvement when originally submitted was ~11% (43 to 38 secs) for operation [2]. At the time, the repository had 117220 commits; it now has 137537 commits. Signed-off-by: Dan McGee Signed-off-by: Junio C Hamano --- tree-walk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tree-walk.c') diff --git a/tree-walk.c b/tree-walk.c index 9be800760..f386151ce 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -591,8 +591,8 @@ int tree_entry_interesting(const struct name_entry *entry, ps->max_depth); } - /* Does the base match? */ - if (!strncmp(base_str, match, baselen)) { + /* Either there must be no base, or the base must match. */ + if (baselen == 0 || !strncmp(base_str, match, baselen)) { if (match_entry(entry, pathlen, match + baselen, matchlen - baselen, &never_interesting)) -- cgit v1.2.1