Skip to content

Commit

Permalink
Micro-optimize prepare_alt_odb
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed May 27, 2007
1 parent d079837 commit 7dc24aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7dc24aa

Please sign in to comment.