git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 1/3] Remove "pathlen" from "struct name_entry"
Date: Wed, 21 Mar 2007 10:07:46 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0703211007160.6730@woody.linux-foundation.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0703210955370.6730@woody.linux-foundation.org>


Since we have the "tree_entry_len()" helper function these days, and
don't need to do a full strlen(), there's no point in saving the path
length - it's just redundant information.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 builtin-grep.c         |    2 +-
 builtin-pack-objects.c |    2 +-
 merge-tree.c           |    9 +++++----
 tree-walk.c            |    6 ++----
 tree-walk.h            |    1 -
 tree.c                 |    9 +++++----
 6 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 4510d35..1348cc9 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -378,7 +378,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
 			 * decide if we want to descend into "abc"
 			 * directory.
 			 */
-			strcpy(path_buf + len + entry.pathlen, "/");
+			strcpy(path_buf + len + tree_entry_len(entry.path, entry.sha1), "/");
 
 		if (!pathspec_matches(paths, down))
 			;
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 73d448b..9231b65 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -854,7 +854,7 @@ static void add_pbase_object(struct tree_desc *tree,
 		unsigned long size;
 		enum object_type type;
 
-		if (entry.pathlen != cmplen ||
+		if (tree_entry_len(entry.path, entry.sha1) != cmplen ||
 		    memcmp(entry.path, name, cmplen) ||
 		    !has_sha1_file(entry.sha1) ||
 		    (type = sha1_object_info(entry.sha1, &size)) < 0)
diff --git a/merge-tree.c b/merge-tree.c
index b2867ba..3b8d9e6 100644
--- a/merge-tree.c
+++ b/merge-tree.c
@@ -188,7 +188,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
 
 static int unresolved_directory(const char *base, struct name_entry n[3])
 {
-	int baselen;
+	int baselen, pathlen;
 	char *newbase;
 	struct name_entry *p;
 	struct tree_desc t[3];
@@ -205,10 +205,11 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
 	if (!S_ISDIR(p->mode))
 		return 0;
 	baselen = strlen(base);
-	newbase = xmalloc(baselen + p->pathlen + 2);
+	pathlen = tree_entry_len(p->path, p->sha1);
+	newbase = xmalloc(baselen + pathlen + 2);
 	memcpy(newbase, base, baselen);
-	memcpy(newbase + baselen, p->path, p->pathlen);
-	memcpy(newbase + baselen + p->pathlen, "/", 2);
+	memcpy(newbase + baselen, p->path, pathlen);
+	memcpy(newbase + baselen + pathlen, "/", 2);
 
 	buf0 = fill_tree_descriptor(t+0, n[0].sha1);
 	buf1 = fill_tree_descriptor(t+1, n[1].sha1);
diff --git a/tree-walk.c b/tree-walk.c
index a4a4e2a..1869bae 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -20,8 +20,8 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
 static int entry_compare(struct name_entry *a, struct name_entry *b)
 {
 	return base_name_compare(
-			a->path, a->pathlen, a->mode,
-			b->path, b->pathlen, b->mode);
+			a->path, tree_entry_len(a->path, a->sha1), a->mode,
+			b->path, tree_entry_len(b->path, b->sha1), b->mode);
 }
 
 static void entry_clear(struct name_entry *a)
@@ -32,7 +32,6 @@ static void entry_clear(struct name_entry *a)
 static void entry_extract(struct tree_desc *t, struct name_entry *a)
 {
 	a->sha1 = tree_entry_extract(t, &a->path, &a->mode);
-	a->pathlen = tree_entry_len(a->path, a->sha1);
 }
 
 void update_tree_entry(struct tree_desc *desc)
@@ -93,7 +92,6 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
 
 	entry->path = path;
 	len = strlen(path);
-	entry->pathlen = len;
 
 	path += len + 1;
 	entry->sha1 = (const unsigned char *) path;
diff --git a/tree-walk.h b/tree-walk.h
index a0d7afd..149393a 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -10,7 +10,6 @@ struct name_entry {
 	const unsigned char *sha1;
 	const char *path;
 	unsigned int mode;
-	int pathlen;
 };
 
 static inline int tree_entry_len(const char *name, const unsigned char *sha1)
diff --git a/tree.c b/tree.c
index 24f8fb6..705a481 100644
--- a/tree.c
+++ b/tree.c
@@ -101,14 +101,15 @@ int read_tree_recursive(struct tree *tree,
 		if (S_ISDIR(entry.mode)) {
 			int retval;
 			char *newbase;
+			unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
 
-			newbase = xmalloc(baselen + 1 + entry.pathlen);
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
-			memcpy(newbase + baselen, entry.path, entry.pathlen);
-			newbase[baselen + entry.pathlen] = '/';
+			memcpy(newbase + baselen, entry.path, pathlen);
+			newbase[baselen + pathlen] = '/';
 			retval = read_tree_recursive(lookup_tree(entry.sha1),
 						     newbase,
-						     baselen + entry.pathlen + 1,
+						     baselen + pathlen + 1,
 						     stage, match, fn);
 			free(newbase);
 			if (retval)
-- 
1.5.1.rc1.13.g0872-dirty

  reply	other threads:[~2007-03-21 17:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-21 17:07 [PATCH 0/3] Clean up and optimize tree walking some more Linus Torvalds
2007-03-21 17:07 ` Linus Torvalds [this message]
2007-03-21 17:08 ` [PATCH 2/3] Initialize tree descriptors with a helper function rather than by hand Linus Torvalds
2007-03-21 17:09 ` [PATCH 3/3] Switch over tree descriptors to contain a pre-parsed entry Linus Torvalds
2007-03-21 18:32 ` Resend: [PATCH 0/3] Clean up and optimize tree walking some more Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0703211007160.6730@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).