[PATCH v3 2/2] sha1_file: improve sha1_file_name() perfs
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jan 18, 2018, 10:08 UTC
- Message-ID
- <20180118100854.22467-2-chriscool@tuxfamily.org>
- In-Reply-To
- <20180118100854.22467-1-chriscool@tuxfamily.org>
As sha1_file_name() could be performance sensitive, let's make it faster by using strbuf_addstr() and strbuf_addc() instead of strbuf_addf().
Helped-by: Derrick Stolee <stolee@gmail.com> Helped-by: Jeff Hostetler <git@jeffhostetler.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> --- sha1_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
So compared to v2 I just removed the call to strbuf_grow() and the related computation.
diff --git a/sha1_file.c b/sha1_file.c index f66c21b2da..4f7f17a24c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -323,8 +323,8 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1) void sha1_file_name(struct strbuf *buf, const unsigned char *sha1) { - strbuf_addf(buf, "%s/", get_object_directory()); - + strbuf_addstr(buf, get_object_directory()); + strbuf_addch(buf, '/'); fill_sha1_path(buf, sha1); }
-- 2.16.0.rc2.3.g7330290b09