From: Jay Soffian <jaysoffian@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] builtin-branch: improve output when displaying remote branches
Date: Fri, 13 Feb 2009 01:45:33 -0500 [thread overview]
Message-ID: <76718490902122245q6f530bb5sc85a65e065966eda@mail.gmail.com> (raw)
In-Reply-To: <7v7i3ug7y9.fsf@gitster.siamese.dyndns.org>
On Fri, Feb 13, 2009 at 1:35 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> + if (prefix && !prefixcmp(dst, prefix))
>> + return xstrdup(skip_prefix(dst, prefix));
>> + else
>> + return xstrdup(dst);
>> +}
>
> I wonder modern compilers are clever enough to optimze the above to
> something more like:
>
> pfxlen = prefix ? strlen(prefix) : 0;
> if (pfxlen && !strncmp(dst, prefix, pfxlen))
> return xstrdup(dst + pfxlen);
> else
> return xstrdup(dst);
>
> given that skip_prefix is an inline function but prefixcmp is not
> (anymore), perhaps not.
>
>> static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
>> {
>> struct ref_list *ref_list = (struct ref_list*)(cb_data);
>> struct ref_item *newitem;
>> struct commit *commit;
>> int kind;
>> - int len;
>> + const char *prefix, *orig_refname = refname;
>>
>> /* Detect kind */
>> if (!prefixcmp(refname, "refs/heads/")) {
>> kind = REF_LOCAL_BRANCH;
>> refname += 11;
>> + prefix = "refs/heads/";
>> } else if (!prefixcmp(refname, "refs/remotes/")) {
>> kind = REF_REMOTE_BRANCH;
>> refname += 13;
>> + prefix = "refs/remotes/";
>> } else
>> return 0;
>
> Once you start making each case arm do more things, it might make sense to
> rewrite the above unrolled loop into something like this:
>
> static struct {
> int kind;
> const char *prefix;
> int pfxlen;
> } ref_kind[] = {
> { REF_LOCAL_BRANCH, "refs/heads/", 11 },
> { REF_REMOTE_BRANCH, "refs/remotes/", 13 },
> };
>
> for (i = 0; i < ARRAY_SIZE(ref_kind); i++) {
> prefix = ref_kind[i].prefix;
> if (strncmp(refname, prefix, ref_kind[i].pfxlen))
> continue;
> kind = ref_kind[i].kind;
> refname += ref_kind[i].pfxlen;
> break;
> }
> if (ARRAY_SIZE(ref_kind) <= i)
> return 0;
>
> Then we can later add new elements more easily, e.g.
>
> { REF_TOPGIT_BASE, "refs/top-base/", 14 },
> ;-)
This strikes me as premature optimization. We're just emitting a few
branch names here. I'm beginning to lose my motivation to keep working
on this patch. I just wanted to improve the UI slightly. :-(
j.
next prev parent reply other threads:[~2009-02-13 6:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-10 11:01 [PATCH] builtin-branch: improve output when displaying remote branches Jay Soffian
2009-02-11 6:47 ` Jay Soffian
2009-02-12 3:49 ` Junio C Hamano
2009-02-12 4:30 ` Jay Soffian
2009-02-12 5:42 ` Junio C Hamano
2009-02-13 5:34 ` [PATCH v2] " Jay Soffian
2009-02-13 6:35 ` Junio C Hamano
2009-02-13 6:45 ` Jay Soffian [this message]
2009-02-13 7:52 ` Junio C Hamano
2009-02-13 8:06 ` Jay Soffian
2009-02-13 9:40 ` [PATCH v3] " Jay Soffian
2009-02-13 6:47 ` [PATCH v2] " martin f krafft
2009-02-13 7:36 ` Junio C Hamano
2009-02-13 7:37 ` Johannes Sixt
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=76718490902122245q6f530bb5sc85a65e065966eda@mail.gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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 NNTP newsgroup(s).