git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Christian Couder
Message 2 of 2 in “sha1_file: remove static strbuf from sha1_file_name()”
  1. 1/2 sha1_file: remove static strbuf from sha1_file_name()Christian Couder, Jan 18, 2018
  2. 2/2 sha1_file: improve sha1_file_name() perfsChristian Couder, Jan 18, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.