Merge branch 'ds/for-each-file-in-obj-micro-optim'
authorJunio C Hamano <gitster@pobox.com>
Wed, 13 Dec 2017 21:28:57 +0000 (13:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Dec 2017 21:28:57 +0000 (13:28 -0800)
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()

sha1_file.c
t/perf/p4211-line-log.sh
index b44f5247caa9389f8d1c7643b7d9d99418d21f72..3da70ac650a8cdeca6ef8a6a424a7740d38267d5 100644 (file)
@@ -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);
 
index e0ed05907c7277def1e9fcda15bd1e1fe98ae6cc..392bcc0e51f8ad907916851016157b12ea134835 100755 (executable)
@@ -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