Skip to content

Commit 4de707e

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: introduce parsing functions for each valid atom
Parsing atoms is done in populate_value(), this is repetitive and hence expensive. Introduce a parsing function which would let us parse atoms beforehand and store the required details into the 'used_atom' structure for further usage. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Helped-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b072add commit 4de707e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

ref-filter.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static int need_color_reset_at_eol;
3636
static struct {
3737
const char *name;
3838
cmp_type cmp_type;
39+
void (*parser)(struct used_atom *atom, const char *arg);
3940
} valid_atom[] = {
4041
{ "refname" },
4142
{ "objecttype" },
@@ -114,6 +115,7 @@ struct atom_value {
114115
int parse_ref_filter_atom(const char *atom, const char *ep)
115116
{
116117
const char *sp;
118+
const char *arg;
117119
int i, at;
118120

119121
sp = atom;
@@ -132,16 +134,16 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
132134
/* Is the atom a valid one? */
133135
for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
134136
int len = strlen(valid_atom[i].name);
137+
135138
/*
136139
* If the atom name has a colon, strip it and everything after
137140
* it off - it specifies the format for this entry, and
138141
* shouldn't be used for checking against the valid_atom
139142
* table.
140143
*/
141-
const char *formatp = strchr(sp, ':');
142-
if (!formatp || ep < formatp)
143-
formatp = ep;
144-
if (len == formatp - sp && !memcmp(valid_atom[i].name, sp, len))
144+
arg = memchr(sp, ':', ep - sp);
145+
if (len == (arg ? arg : ep) - sp &&
146+
!memcmp(valid_atom[i].name, sp, len))
145147
break;
146148
}
147149

@@ -154,6 +156,10 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
154156
REALLOC_ARRAY(used_atom, used_atom_cnt);
155157
used_atom[at].name = xmemdupz(atom, ep - atom);
156158
used_atom[at].type = valid_atom[i].cmp_type;
159+
if (arg)
160+
arg = used_atom[at].name + (arg - atom) + 1;
161+
if (valid_atom[i].parser)
162+
valid_atom[i].parser(&used_atom[at], arg);
157163
if (*atom == '*')
158164
need_tagged = 1;
159165
if (!strcmp(used_atom[at].name, "symref"))

0 commit comments

Comments
 (0)