From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
"git\@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [RFC-PATCHv6 4/4] pathspec: allow querying for attributes
Date: Wed, 18 May 2016 08:39:06 -0700 [thread overview]
Message-ID: <xmqqa8jntlyd.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqposkv3c9.fsf@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Tue, 17 May 2016 13:25:58 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> The mention of the possibility is purely as a hint useful for a
> possible enhancement in the far future. If we ever want to support
> something like this:
>
> ":(attr-expression (VAR1=VAL1 | VAR1=VAL2) & VAR2)"
>
> you can remember that you can put VAR1 and VAR2 in attr_check to
> grab values for VAR1 and VAR2 (even though VAR1 is mentioned twice
> in the expression), and use them in the evaluation you will perform.
>
>> So for the matching we would need to get the order right, i.e.
>>
>> const char *inspect_name = git_attr_name(item.attr_match[i].attr);
>> for (j=0; j < p.attr_check.check_nr; j++) {
>> const char *cur_name = git_attr_name(p.attr_check.check[j].attr);
>> if (!strcmp(inspect_name, cur_name))
>> break;
>
> You do not strcmp() when you have attributes. They are interned so
> that you can compare their addresses. That makes it somewhat
> cheaper.
>
> Once you start "expression over random attributes", you'd need to
> map attr => value somehow. The format attr_check structure gives
> you, i.e. a list of <attr, value>, is aimed at compactness than
> random hashmap-like access. If the caller wants a hashmap-like
> access for performance purposes, the caller does that itself.
To expand this a bit, I actually do not think hashmap-like access is
necessary even in such an application.
An implementation of the evaluator, at least a production-quality
one, for the attr expression example shown above is unlikely to keep
the expression in a single string "(VAR1=VAL1 | VAR1=VAL2) & VAR2".
Instead it would use a parse tree with nodes that represent
operators (e.g. OR, AND, "=", etc.) and terms (e.g. attribute
reference VAR1, VAR2, and constatnts "VAL1", "VAL2") as its internal
representation.
And a node in such a parse tree that refers to an attribute VAR1
would unlikely to keep a "const char *" that is "VAR1". The node
would have a field that stores an index into the attr_check.check[]
array when the textual expression is "compiled" into a parse tree
and the set of attributes the expression uses (hence it needs to
ask the attributes API about, to prepare attr_check array) is
identified.
When "evaluating" the parse-tree, a node that refers to an attribute
has an index into attr_check.check[] array, so there is no need for
a loop like the one shown above at all.
When "showing" the expression (for debugging purposes), it would
grab the "index into the attr_check.check[] array" from the node,
and the element in that array is an <attr, value> pair, so it can
use git_attr_name() to obtain the attribute name.
next prev parent reply other threads:[~2016-05-18 15:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-17 3:13 [RFC-PATCHv6 0/4] pathspec attrs [WAS pathspec labels [WAS submodule groups]] Stefan Beller
2016-05-17 3:13 ` [RFC-PATCHv6 1/4] Documentation: fix a typo Stefan Beller
2016-05-17 3:13 ` [RFC-PATCHv6 2/4] pathspec: move long magic parsing out of prefix_pathspec Stefan Beller
2016-05-17 3:13 ` [RFC-PATCHv6 3/4] pathspec: move prefix check out of the inner loop Stefan Beller
2016-05-17 3:13 ` [RFC-PATCHv6 4/4] pathspec: allow querying for attributes Stefan Beller
2016-05-17 4:23 ` Junio C Hamano
2016-05-17 16:45 ` Stefan Beller
2016-05-17 5:03 ` Junio C Hamano
2016-05-17 17:03 ` Stefan Beller
2016-05-17 17:34 ` Junio C Hamano
2016-05-17 17:45 ` Stefan Beller
2016-05-17 18:05 ` Junio C Hamano
2016-05-17 18:10 ` Stefan Beller
2016-05-17 18:29 ` Junio C Hamano
2016-05-17 19:23 ` Stefan Beller
2016-05-17 20:25 ` Junio C Hamano
2016-05-18 15:39 ` Junio C Hamano [this message]
2016-05-17 4:14 ` [RFC-PATCHv6 0/4] pathspec attrs [WAS pathspec labels [WAS submodule groups]] 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=xmqqa8jntlyd.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=sbeller@google.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