diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-12-13 13:28:57 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-12-13 13:28:57 -0800 |
commit | 97e1f857fc8c7a9ba2b1179d58cc2b6b68a88437 (patch) | |
tree | 7edf80a30bdc597f41f6406f68ae362d36dbce43 /sha1_file.c | |
parent | 36ddee941e496685739292e422772fe264ff8a8a (diff) | |
parent | 163ee5e635233f8614c29c11c9b8ee02902d65c4 (diff) | |
download | git-97e1f857fc8c7a9ba2b1179d58cc2b6b68a88437.tar.gz |
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()
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sha1_file.c b/sha1_file.c index b44f5247ca..3da70ac650 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -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); |