From: Junio C Hamano <gitster@pobox.com>
To: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] path: remove redundant function calls
Date: Tue, 03 Mar 2026 08:39:18 -0800 [thread overview]
Message-ID: <xmqqwlzseukp.fsf@gitster.g> (raw)
In-Reply-To: <20260302142138.712273-4-jayatheerthkulkarni2005@gmail.com> (K. Jayatheerth's message of "Mon, 2 Mar 2026 19:51:38 +0530")
K Jayatheerth <jayatheerthkulkarni2005@gmail.com> 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 <jayatheerthkulkarni2005@gmail.com>
> ---
> 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;
next prev parent reply other threads:[~2026-03-03 16:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 14:21 [PATCH 0/3] path: clean up few things K Jayatheerth
2026-03-02 14:21 ` [PATCH 1/3] path: remove unused header K Jayatheerth
2026-03-02 14:21 ` [PATCH 2/3] path: use the right datatype K Jayatheerth
2026-03-03 13:42 ` Patrick Steinhardt
2026-03-03 16:21 ` Junio C Hamano
2026-03-02 14:21 ` [PATCH 3/3] path: remove redundant function calls K Jayatheerth
2026-03-03 13:42 ` Patrick Steinhardt
2026-03-03 16:39 ` Junio C Hamano [this message]
2026-03-04 13:04 ` [PATCH v2 0/3] clean up a few things K Jayatheerth
2026-03-04 13:05 ` [PATCH v2 1/3] path: remove unused header K Jayatheerth
2026-03-04 13:05 ` [PATCH v2 2/3] path: use size_t for dir_prefix length K Jayatheerth
2026-03-04 17:15 ` Junio C Hamano
2026-03-04 13:05 ` [PATCH v2 3/3] path: remove redundant function calls K Jayatheerth
2026-03-05 12:53 ` [PATCH v3 0/3] clean up a few things K Jayatheerth
2026-03-05 12:53 ` [PATCH v3 1/3] path: remove unused header K Jayatheerth
2026-03-05 12:53 ` [PATCH v3 2/3] path: use size_t for dir_prefix length K Jayatheerth
2026-03-05 12:53 ` [PATCH v3 3/3] path: remove redundant function calls K Jayatheerth
2026-03-05 19:36 ` [PATCH v3 0/3] clean up a few things Junio C Hamano
2026-03-06 1:47 ` K Jayatheerth
2026-03-06 1:59 ` K Jayatheerth
2026-03-06 21:58 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwlzseukp.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jayatheerthkulkarni2005@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.