git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: Re: [PATCH v2 3/7] reftable/refname: refactor binary search over refnames
Date: Tue, 2 Apr 2024 19:15:18 +0200	[thread overview]
Message-ID: <Zgw9Jt9nkoupo38Q@tanuki> (raw)
In-Reply-To: <zvw6ezlchqyl5tq4zuia7az5b3i4swwvtm42muwe4i7gngswgz@ztujhb4ruewm>

[-- Attachment #1: Type: text/plain, Size: 4208 bytes --]

On Tue, Apr 02, 2024 at 11:27:01AM -0500, Justin Tobler wrote:
> On 24/03/25 11:10AM, Patrick Steinhardt wrote:
> > It is comparatively hard to understand how exactly the binary search
> > over refnames works given that the function and variable names are not
> > exactly easy to grasp. Rename them to make this more obvious. This
> > should not result in any change in behaviour.
> > 
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> >  reftable/refname.c | 44 ++++++++++++++++++++++----------------------
> >  1 file changed, 22 insertions(+), 22 deletions(-)
> > 
> > diff --git a/reftable/refname.c b/reftable/refname.c
> > index 64eba1b886..9ec488d727 100644
> > --- a/reftable/refname.c
> > +++ b/reftable/refname.c
> > @@ -12,15 +12,15 @@
> >  #include "refname.h"
> >  #include "reftable-iterator.h"
> >  
> > -struct find_arg {
> > -	char **names;
> > -	const char *want;
> > +struct refname_needle_lesseq_args {
> > +	char **haystack;
> > +	const char *needle;
> >  };
> >  
> > -static int find_name(size_t k, void *arg)
> > +static int refname_needle_lesseq(size_t k, void *arg)
> >  {
> > -	struct find_arg *f_arg = arg;
> > -	return strcmp(f_arg->names[k], f_arg->want) >= 0;
> > +	struct refname_needle_lesseq_args *f_arg = arg;
> 
> nit: Looks like the `f_arg` variable name is a remnant from when the
> type was called `find_arg`. Do we want to rename this to `args`? We 
> could also rename `void *arg` to `void *_args`.

Yup.

> > +	return strcmp(f_arg->needle, f_arg->haystack[k]) <= 0;
> >  }
> >  
> >  static int modification_has_ref(struct modification *mod, const char *name)
> > @@ -29,21 +29,21 @@ static int modification_has_ref(struct modification *mod, const char *name)
> >  	int err = 0;
> >  
> >  	if (mod->add_len > 0) {
> > -		struct find_arg arg = {
> > -			.names = mod->add,
> > -			.want = name,
> > +		struct refname_needle_lesseq_args arg = {
> > +			.haystack = mod->add,
> > +			.needle = name,
> >  		};
> > -		size_t idx = binsearch(mod->add_len, find_name, &arg);
> > +		size_t idx = binsearch(mod->add_len, refname_needle_lesseq, &arg);
> >  		if (idx < mod->add_len && !strcmp(mod->add[idx], name))
> >  			return 0;
> >  	}
> >  
> >  	if (mod->del_len > 0) {
> > -		struct find_arg arg = {
> > -			.names = mod->del,
> > -			.want = name,
> > +		struct refname_needle_lesseq_args arg = {
> 
> nit: In the other commits we use `args`. Do we want to be consistent?

Yeah. Given that it was my own argument to be consistent across
callsites I should rather make it truly consistent :)

Patrick

> -Justin
> 
> > +			.haystack = mod->del,
> > +			.needle = name,
> >  		};
> > -		size_t idx = binsearch(mod->del_len, find_name, &arg);
> > +		size_t idx = binsearch(mod->del_len, refname_needle_lesseq, &arg);
> >  		if (idx < mod->del_len && !strcmp(mod->del[idx], name))
> >  			return 1;
> >  	}
> > @@ -71,11 +71,11 @@ static int modification_has_ref_with_prefix(struct modification *mod,
> >  	int err = 0;
> >  
> >  	if (mod->add_len > 0) {
> > -		struct find_arg arg = {
> > -			.names = mod->add,
> > -			.want = prefix,
> > +		struct refname_needle_lesseq_args arg = {
> > +			.haystack = mod->add,
> > +			.needle = prefix,
> >  		};
> > -		size_t idx = binsearch(mod->add_len, find_name, &arg);
> > +		size_t idx = binsearch(mod->add_len, refname_needle_lesseq, &arg);
> >  		if (idx < mod->add_len &&
> >  		    !strncmp(prefix, mod->add[idx], strlen(prefix)))
> >  			goto done;
> > @@ -90,11 +90,11 @@ static int modification_has_ref_with_prefix(struct modification *mod,
> >  			goto done;
> >  
> >  		if (mod->del_len > 0) {
> > -			struct find_arg arg = {
> > -				.names = mod->del,
> > -				.want = ref.refname,
> > +			struct refname_needle_lesseq_args arg = {
> > +				.haystack = mod->del,
> > +				.needle = ref.refname,
> >  			};
> > -			size_t idx = binsearch(mod->del_len, find_name, &arg);
> > +			size_t idx = binsearch(mod->del_len, refname_needle_lesseq, &arg);
> >  			if (idx < mod->del_len &&
> >  			    !strcmp(ref.refname, mod->del[idx]))
> >  				continue;
> > -- 
> > 2.44.GIT
> > 
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-04-02 17:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 12:22 [PATCH 0/7] reftable: improvements for the `binsearch()` mechanism Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 1/7] reftable/basics: fix return type of `binsearch()` to be `size_t` Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 2/7] reftable/basics: improve `binsearch()` test Patrick Steinhardt
2024-03-22 18:46   ` Justin Tobler
2024-03-25 10:07     ` Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 3/7] reftable/refname: refactor binary search over refnames Patrick Steinhardt
2024-03-22 18:55   ` Justin Tobler
2024-03-25 10:07     ` Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 4/7] reftable/block: refactor binary search over restart points Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 5/7] reftable/block: fix error handling when searching " Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 6/7] reftable/record: extract function to decode key lengths Patrick Steinhardt
2024-03-22 12:22 ` [PATCH 7/7] reftable/block: avoid decoding keys when searching restart points Patrick Steinhardt
2024-03-25 10:10 ` [PATCH v2 0/7] reftable: improvements for the `binsearch()` mechanism Patrick Steinhardt
2024-03-25 10:10   ` [PATCH v2 1/7] reftable/basics: fix return type of `binsearch()` to be `size_t` Patrick Steinhardt
2024-03-25 10:10   ` [PATCH v2 2/7] reftable/basics: improve `binsearch()` test Patrick Steinhardt
2024-03-25 10:10   ` [PATCH v2 3/7] reftable/refname: refactor binary search over refnames Patrick Steinhardt
2024-04-02 16:27     ` Justin Tobler
2024-04-02 17:15       ` Patrick Steinhardt [this message]
2024-03-25 10:10   ` [PATCH v2 4/7] reftable/block: refactor binary search over restart points Patrick Steinhardt
2024-04-02 16:42     ` Justin Tobler
2024-04-02 17:15       ` Patrick Steinhardt
2024-04-02 17:46         ` Justin Tobler
2024-04-03  6:01           ` Patrick Steinhardt
2024-03-25 10:10   ` [PATCH v2 5/7] reftable/block: fix error handling when searching " Patrick Steinhardt
2024-03-25 10:10   ` [PATCH v2 6/7] reftable/record: extract function to decode key lengths Patrick Steinhardt
2024-03-25 10:11   ` [PATCH v2 7/7] reftable/block: avoid decoding keys when searching restart points Patrick Steinhardt
2024-04-02 16:47     ` Justin Tobler
2024-04-02 17:15       ` Patrick Steinhardt
2024-04-02 17:24 ` [PATCH v3 0/7] reftable: improvements for the `binsearch()` mechanism Patrick Steinhardt
2024-04-02 17:24   ` [PATCH v3 1/7] reftable/basics: fix return type of `binsearch()` to be `size_t` Patrick Steinhardt
2024-04-02 17:24   ` [PATCH v3 2/7] reftable/basics: improve `binsearch()` test Patrick Steinhardt
2024-04-02 17:24   ` [PATCH v3 3/7] reftable/refname: refactor binary search over refnames Patrick Steinhardt
2024-04-02 17:24   ` [PATCH v3 4/7] reftable/block: refactor binary search over restart points Patrick Steinhardt
2024-04-02 17:24   ` [PATCH v3 5/7] reftable/block: fix error handling when searching " Patrick Steinhardt
2024-04-02 17:25   ` [PATCH v3 6/7] reftable/record: extract function to decode key lengths Patrick Steinhardt
2024-04-02 17:25   ` [PATCH v3 7/7] reftable/block: avoid decoding keys when searching restart points Patrick Steinhardt
2024-04-02 17:49   ` [PATCH v3 0/7] reftable: improvements for the `binsearch()` mechanism Justin Tobler
2024-04-03  6:03 ` [PATCH v4 " Patrick Steinhardt
2024-04-03  6:03   ` [PATCH v4 1/7] reftable/basics: fix return type of `binsearch()` to be `size_t` Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 2/7] reftable/basics: improve `binsearch()` test Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 3/7] reftable/refname: refactor binary search over refnames Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 4/7] reftable/block: refactor binary search over restart points Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 5/7] reftable/block: fix error handling when searching " Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 6/7] reftable/record: extract function to decode key lengths Patrick Steinhardt
2024-04-03  6:04   ` [PATCH v4 7/7] reftable/block: avoid decoding keys when searching restart points Patrick Steinhardt

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zgw9Jt9nkoupo38Q@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).