path: root/tree-walk.c
diff options
authorNguyễn Thái Ngọc Duy <>2010-12-15 15:02:42 (GMT)
committerJunio C Hamano <>2011-02-03 22:08:16 (GMT)
commit48932677d62e426b3f26ac236384cb5195fb9dfd (patch)
treed58115641e35cc305af9b5f48e6fcf39f5cfee35 /tree-walk.c
parent3bd2bcfa982c69c0f5722c3dfe72b15cd0469d15 (diff)
diff-tree: convert base+baselen to writable strbuf
In traversing trees, a full path is splitted into two parts: base directory and entry. They are however quite often concatenated whenever a full path is needed. Current code allocates a new buffer, do two memcpy(), use it, then release. Instead this patch turns "base" to a writable, extendable buffer. When a concatenation is needed, the callee only needs to append "entry" to base, use it, then truncate the entry out again. "base" must remain unchanged before and after entering a function. This avoids quite a bit of malloc() and memcpy(). Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'tree-walk.c')
1 files changed, 3 insertions, 2 deletions
diff --git a/tree-walk.c b/tree-walk.c
index 522bb6b..21028d0 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -468,12 +468,13 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
* - negative for "no, and no subsequent entries will be either"
int tree_entry_interesting(const struct name_entry *entry,
- const char *base, int baselen,
+ const struct strbuf *base_buf,
const struct pathspec *ps)
int i;
- int pathlen;
+ int pathlen, baselen = base_buf->len;
int never_interesting = -1;
+ const char *base = base_buf->buf;
if (!ps || !ps->nr)
return 2;