From: Junio C Hamano Date: Tue, 03 Mar 2026 16:39:18 GMT Subject: Re: [PATCH 3/3] path: remove redundant function calls Message-ID: In-Reply-To: <20260302142138.712273-4-jayatheerthkulkarni2005@gmail.com> K Jayatheerth writes: > We fetch the exact same setting up to four times. > We fix this by evaluating it once, storing it in a local variable, > and referencing that variable. > > Signed-off-by: K Jayatheerth > --- > path.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) The function body is guarded with "we initialize this just once and return the value stored in a structure member", so 3 among four of these calls incur only cost for a no-op call/return, but using a temporary variable on this caller's side makes it clear that we are not expecting any recomputation in the callee. > diff --git a/path.c b/path.c > index 56be5e1726..5cd38b2a16 100644 > --- a/path.c > +++ b/path.c > @@ -741,18 +741,18 @@ int calc_shared_perm(struct repository *repo, > int mode) > { > int tweak; > - > - if (repo_settings_get_shared_repository(repo) < 0) > - tweak = -repo_settings_get_shared_repository(repo); > + int shared_repo = repo_settings_get_shared_repository(repo); > + if (shared_repo < 0) > + tweak = -shared_repo; > else > - tweak = repo_settings_get_shared_repository(repo); > + tweak = shared_repo; > > if (!(mode & S_IWUSR)) > tweak &= ~0222; > if (mode & S_IXUSR) > /* Copy read bits to execute bits */ > tweak |= (tweak & 0444) >> 2; > - if (repo_settings_get_shared_repository(repo) < 0) > + if (shared_repo < 0) > mode = (mode & ~0777) | tweak; > else > mode |= tweak;