提交 97e1f857 编写于 作者: J Junio C Hamano

Merge branch 'ds/for-each-file-in-obj-micro-optim'

The code to iterate over loose object files got optimized.

* ds/for-each-file-in-obj-micro-optim:
  sha1_file: use strbuf_add() instead of strbuf_addf()
......@@ -1964,7 +1964,6 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
origlen = path->len;
strbuf_complete(path, '/');
strbuf_addf(path, "%02x", subdir_nr);
baselen = path->len;
dir = opendir(path->buf);
if (!dir) {
......@@ -1975,15 +1974,18 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
}
oid.hash[0] = subdir_nr;
strbuf_addch(path, '/');
baselen = path->len;
while ((de = readdir(dir))) {
size_t namelen;
if (is_dot_or_dotdot(de->d_name))
continue;
namelen = strlen(de->d_name);
strbuf_setlen(path, baselen);
strbuf_addf(path, "/%s", de->d_name);
if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2 &&
strbuf_add(path, de->d_name, namelen);
if (namelen == GIT_SHA1_HEXSZ - 2 &&
!hex_to_bytes(oid.hash + 1, de->d_name,
GIT_SHA1_RAWSZ - 1)) {
if (obj_cb) {
......@@ -2002,7 +2004,7 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
}
closedir(dir);
strbuf_setlen(path, baselen);
strbuf_setlen(path, baselen - 1);
if (!r && subdir_cb)
r = subdir_cb(subdir_nr, path->buf, data);
......
......@@ -35,4 +35,8 @@ test_perf 'git log --oneline --raw --parents' '
git log --oneline --raw --parents >/dev/null
'
test_perf 'git log --oneline --raw --parents -1000' '
git log --oneline --raw --parents -1000 >/dev/null
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册