All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC 4/4] attr: avoid heavy work when we know the specified attr is not defined
Date: Tue, 09 Dec 2014 16:18:57 -0800	[thread overview]
Message-ID: <xmqqsigojr0u.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1418133205-18213-5-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Tue, 9 Dec 2014 20:53:25 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> +static void collect_selected_attrs(const char *path, int num,
> +				   struct git_attr_check *check)
> +{
> +	struct attr_stack *stk;
> +	int i, pathlen, rem, dirlen;
> +	int basename_offset;
> +
> +	pathlen = split_path(path, &dirlen, &basename_offset);
> +	prepare_attr_stack(path, dirlen);
> +	if (cannot_trust_maybe_real) {
> +		for (i = 0; i < git_attr_nr; i++)
> +			check_all_attr[i].value = ATTR__UNKNOWN;

Judging from the fact that

 (1) the only caller calls this function in this fashion based on the
     setting of "cannot-trust" bit,

 (2) this and the other function the only caller calls share the
     same code in their beginning part, and

 (3) the body of the if() statement here duplicates the code from
     collect_all_attrs(),

I smell that a much better split is possible.

Why isn't this all inside a single function collect_all_attrs()?
That single function may no longer be collect_ALL_attrs, so renaming
it to collect_attrs() is fine, but then that function may have this
if () to initialize all of them to ATTR__UNKNOWN or do the else part
we see below, and when organized that way we do not need to have
duplicated code (or split_path() helper function), no?

> +	} else {
> +		rem = num;
> +		for (i = 0; i < num; i++) {
> +			struct git_attr_check *c;
> +			c = check_all_attr + check[i].attr->attr_nr;
> +			if (check[i].attr->maybe_real)
> +				c->value = ATTR__UNKNOWN;
> +			else {
> +				c->value = ATTR__UNSET;
> +				rem--;
> +			}
> +		}
> +		if (!rem)
> +			return;
> +	}
> +	rem = git_attr_nr;
> +	for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
> +		rem = fill(path, pathlen, basename_offset, stk, rem);
> +}
> +
>  int git_check_attr(const char *path, int num, struct git_attr_check *check)
>  {
>  	int i;
>  
> -	collect_all_attrs(path);
> +	if (cannot_trust_maybe_real)
> +		collect_all_attrs(path);
> +	else
> +		collect_selected_attrs(path, num, check);
>  
>  	for (i = 0; i < num; i++) {
>  		const char *value = check_all_attr[check[i].attr->attr_nr].value;

  reply	other threads:[~2014-12-10  0:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09 13:53 [PATCH/RFC 0/4] some attr optimizations Nguyễn Thái Ngọc Duy
2014-12-09 13:53 ` [PATCH 1/4] attr.c: rename global var attr_nr to git_attr_nr Nguyễn Thái Ngọc Duy
2014-12-09 23:54   ` Junio C Hamano
2014-12-09 13:53 ` [PATCH 2/4] attr.c: split path processing code out of collect_all_attrs() Nguyễn Thái Ngọc Duy
2014-12-09 13:53 ` [PATCH/RFC 3/4] attr: do not attempt to expand when we know it's not a macro Nguyễn Thái Ngọc Duy
2014-12-09 23:27   ` Eric Sunshine
2014-12-09 23:56   ` Junio C Hamano
2014-12-09 13:53 ` [PATCH/RFC 4/4] attr: avoid heavy work when we know the specified attr is not defined Nguyễn Thái Ngọc Duy
2014-12-10  0:18   ` Junio C Hamano [this message]
2014-12-15  0:50     ` Duy Nguyen
2014-12-15 17:30       ` Junio C Hamano
2014-12-27 23:39 ` [PATCH v2 0/3] some attr optimizations Nguyễn Thái Ngọc Duy
2014-12-27 23:39   ` [PATCH v2 1/3] attr.c: rename arg name attr_nr to avoid shadowing the global one Nguyễn Thái Ngọc Duy
2014-12-27 23:39   ` [PATCH v2 2/3] attr: do not attempt to expand when we know it's not a macro Nguyễn Thái Ngọc Duy
2014-12-27 23:59     ` Eric Sunshine
2014-12-27 23:39   ` [PATCH v2 3/3] attr: avoid heavy work when we know the specified attr is not defined Nguyễn Thái Ngọc Duy

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=xmqqsigojr0u.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@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.