From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nicolas Pitre" <nico@fluxnic.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/4] pack v4: avoid strlen() in tree_entry_prefix
Date: Thu, 12 Sep 2013 17:38:01 +0700 [thread overview]
Message-ID: <1378982284-7848-1-git-send-email-pclouds@gmail.com> (raw)
We do know the length of the path name of an tree entry from the tree
dictionary. On an unoptimized build, this cuts down "git rev-list
--objects v1.8.4"'s time from 6.2s to 5.8s. This difference is less on
optimized builds.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
packv4-parse.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/packv4-parse.c b/packv4-parse.c
index c00a014..ae3e6a5 100644
--- a/packv4-parse.c
+++ b/packv4-parse.c
@@ -50,15 +50,17 @@ struct packv4_dict *pv4_create_dict(const unsigned char *data, int dict_size)
return NULL;
}
- dict = xmalloc(sizeof(*dict) + nb_entries * sizeof(dict->offsets[0]));
+ dict = xmalloc(sizeof(*dict) +
+ (nb_entries + 1) * sizeof(dict->offsets[0]));
dict->data = data;
dict->nb_entries = nb_entries;
+ dict->offsets[0] = 0;
cp = data;
for (i = 0; i < nb_entries; i++) {
- dict->offsets[i] = cp - data;
cp += 2;
cp += strlen((const char *)cp) + 1;
+ dict->offsets[i + 1] = cp - data;
}
return dict;
@@ -163,7 +165,8 @@ static void load_path_dict(struct packed_git *p)
p->path_dict = paths;
}
-const unsigned char *get_pathref(struct packed_git *p, unsigned int index)
+const unsigned char *get_pathref(struct packed_git *p, unsigned int index,
+ int *len)
{
if (!p->path_dict)
load_path_dict(p);
@@ -172,6 +175,9 @@ const unsigned char *get_pathref(struct packed_git *p, unsigned int index)
error("%s: index overflow", __func__);
return NULL;
}
+ if (len)
+ *len = p->path_dict->offsets[index + 1] -
+ p->path_dict->offsets[index];
return p->path_dict->data + p->path_dict->offsets[index];
}
@@ -373,9 +379,9 @@ static int copy_canonical_tree_entries(struct packed_git *p, off_t offset,
}
static int tree_entry_prefix(unsigned char *buf, unsigned long size,
- const unsigned char *path, unsigned mode)
+ const unsigned char *path, int path_len,
+ unsigned mode)
{
- int path_len = strlen((const char *)path) + 1;
int mode_len = 0;
int len;
unsigned char mode_buf[8];
@@ -463,14 +469,15 @@ static int decode_entries(struct packed_git *p, struct pack_window **w_curs,
*/
const unsigned char *path, *sha1;
unsigned mode;
- int len;
+ int len, pathlen;
- path = get_pathref(p, what >> 1);
+ path = get_pathref(p, what >> 1, &pathlen);
sha1 = get_sha1ref(p, &scp);
if (!path || !sha1)
return -1;
mode = (path[0] << 8) | path[1];
- len = tree_entry_prefix(*dstp, *sizep, path + 2, mode);
+ len = tree_entry_prefix(*dstp, *sizep,
+ path + 2, pathlen - 2, mode);
if (!len || len + 20 > *sizep)
return -1;
hashcpy(*dstp + len, sha1);
--
1.8.2.83.gc99314b
next reply other threads:[~2013-09-12 10:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 10:38 Nguyễn Thái Ngọc Duy [this message]
2013-09-12 10:38 ` [PATCH 2/4] pack v4: add v4_size to struct delta_base_cache_entry Nguyễn Thái Ngọc Duy
2013-09-13 13:27 ` Nicolas Pitre
2013-09-13 13:59 ` Duy Nguyen
2013-09-14 2:06 ` Nicolas Pitre
2013-09-14 4:22 ` Nicolas Pitre
2013-09-15 7:35 ` Duy Nguyen
2013-09-16 4:42 ` Nicolas Pitre
2013-09-16 5:24 ` Duy Nguyen
2013-09-12 10:38 ` [PATCH 3/4] pack v4: cache flattened v4 trees in delta base cache Nguyễn Thái Ngọc Duy
2013-09-12 10:38 ` [PATCH 4/4] pack v4: make use of cached v4 trees when unpacking Nguyễn Thái Ngọc Duy
2013-09-12 13:29 ` [PATCH 5/4] pack v4: convert v4 tree to canonical format if found in base cache Nguyễn Thái Ngọc Duy
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=1378982284-7848-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=nico@fluxnic.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).