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

[PATCH 2/3] Micro-optimize prepare_alt_odb

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 26, 2007, 05:24 UTC
Message-ID
<20070526052440.GB11957@spearce.org>

Calling getenv() is not that expensive, but its also not free, and its certainly not cheaper than testing to see if alt_odb_tail is not null.

Because we are calling prepare_alt_odb() from within find_sha1_file every time we cannot find an object file locally we want to skip out of prepare_alt_odb() as early as possible once we have initialized our alternate list.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 sha1_file.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 6a5ba63..a3637d7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -376,11 +376,12 @@ void prepare_alt_odb(void)
 {
 	const char *alt;
 
+	if (alt_odb_tail)
+		return;
+
 	alt = getenv(ALTERNATE_DB_ENVIRONMENT);
 	if (!alt) alt = "";
 
-	if (alt_odb_tail)
-		return;
 	alt_odb_tail = &alt_odb_list;
 	link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL, 0);
 
-- 
1.5.2.789.g8ee1
Message 1 of 1 in “Micro-optimize prepare_alt_odb”
  1. 2/3 Micro-optimize prepare_alt_odbShawn O. Pearce, May 26, 2007

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.