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()
This commit is contained in:
Junio C Hamano 2017-12-13 13:28:57 -08:00
Родитель 36ddee941e 163ee5e635
Коммит 97e1f857fc
2 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -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