@matheusbsbs / matheus-bagliano / commits / 7dc24aa5a6
Fork 0

Micro-optimize prepare_alt_odb

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>

Shawn O. Pearce committed May 26, 2007 at 01:24 UTC 7dc24aa5a62cc5f77e6637674581c837f4bdf78e
1 file changed +3 -2
sha1_file.c
+3 -2
@@ -376,11 +376,12 @@ void prepare_alt_odb(void)
376 {
377 const char *alt;
378
379 + if (alt_odb_tail)
380 + return;
381 +
382 alt = getenv(ALTERNATE_DB_ENVIRONMENT);
383 if (!alt) alt = "";
384
382 - if (alt_odb_tail)
383 - return;
385 alt_odb_tail = &alt_odb_list;
386 link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL, 0);
387