Unroll the loop over passes
The passes no longer share much code, and the unrolled code is easier to understand. Use a new index variable instead of num_attr for the second loop, as we are no longer counting attributes but rather indexing through them. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e0a5f9aaae
commit
d68e1c183c
17
attr.c
17
attr.c
@ -191,10 +191,9 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
int lineno, int macro_ok)
|
int lineno, int macro_ok)
|
||||||
{
|
{
|
||||||
int namelen;
|
int namelen;
|
||||||
int num_attr;
|
int num_attr, i;
|
||||||
const char *cp, *name, *states;
|
const char *cp, *name, *states;
|
||||||
struct match_attr *res = NULL;
|
struct match_attr *res = NULL;
|
||||||
int pass;
|
|
||||||
int is_macro;
|
int is_macro;
|
||||||
|
|
||||||
cp = line + strspn(line, blank);
|
cp = line + strspn(line, blank);
|
||||||
@ -226,16 +225,13 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
states = name + namelen;
|
states = name + namelen;
|
||||||
states += strspn(states, blank);
|
states += strspn(states, blank);
|
||||||
|
|
||||||
for (pass = 0; pass < 2; pass++) {
|
/* First pass to count the attr_states */
|
||||||
/* pass 0 counts and allocates, pass 1 fills */
|
|
||||||
for (cp = states, num_attr = 0; *cp; num_attr++) {
|
for (cp = states, num_attr = 0; *cp; num_attr++) {
|
||||||
cp = parse_attr(src, lineno, cp,
|
cp = parse_attr(src, lineno, cp, NULL);
|
||||||
pass ? &(res->state[num_attr]) : NULL);
|
|
||||||
if (!cp)
|
if (!cp)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (pass)
|
|
||||||
break;
|
|
||||||
res = xcalloc(1,
|
res = xcalloc(1,
|
||||||
sizeof(*res) +
|
sizeof(*res) +
|
||||||
sizeof(struct attr_state) * num_attr +
|
sizeof(struct attr_state) * num_attr +
|
||||||
@ -249,7 +245,12 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
}
|
}
|
||||||
res->is_macro = is_macro;
|
res->is_macro = is_macro;
|
||||||
res->num_attr = num_attr;
|
res->num_attr = num_attr;
|
||||||
|
|
||||||
|
/* Second pass to fill the attr_states */
|
||||||
|
for (cp = states, i = 0; *cp; i++) {
|
||||||
|
cp = parse_attr(src, lineno, cp, &(res->state[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user