aboutsummaryrefslogtreecommitdiff
path: root/tree-walk.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2007-03-17 20:06:24 -0700
committerJunio C Hamano <junkio@cox.net>2007-03-18 15:36:59 -0700
commit304de2d2d6afc7500fe9b8f2e22dd0a16a902d8b (patch)
tree5a52190e45bff80e2144a1b9edd590e54c1e4749 /tree-walk.h
parenta0cba10847c85b0becc3c7045a423e3dc8a8f4ae (diff)
downloadgit-304de2d2d6afc7500fe9b8f2e22dd0a16a902d8b.tar.gz
git-304de2d2d6afc7500fe9b8f2e22dd0a16a902d8b.tar.xz
Avoid unnecessary strlen() calls
This is a micro-optimization that grew out of the mailing list discussion about "strlen()" showing up in profiles. We used to pass regular C strings around to the low-level tree walking routines, and while this worked fine, it meant that we needed to call strlen() on strings that the caller always actually knew the size of anyway. So pass the length of the string down wih the string, and avoid unnecessary calls to strlen(). Also, when extracting a pathname from a tree entry, use "tree_entry_len()" instead of strlen(), since the length of the pathname is directly calculable from the decoded tree entry itself without having to actually do another strlen(). This shaves off another ~5-10% from some loads that are very tree intensive (notably doing commit filtering by a pathspec). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>" Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'tree-walk.h')
-rw-r--r--tree-walk.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/tree-walk.h b/tree-walk.h
index e57befa4d..a0d7afd89 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -13,6 +13,11 @@ struct name_entry {
int pathlen;
};
+static inline int tree_entry_len(const char *name, const unsigned char *sha1)
+{
+ return (char *)sha1 - (char *)name - 1;
+}
+
void update_tree_entry(struct tree_desc *);
const unsigned char *tree_entry_extract(struct tree_desc *, const char **, unsigned int *);