Skip to content

Commit b072add

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: introduce struct used_atom
Introduce the 'used_atom' structure to replace the existing implementation of 'used_atom' (which is a list of atoms). This helps us parse atoms beforehand and store required details into the 'used_atom' for future usage. Helped-by: Eric Sunshine <sunshine@sunshineco.com> 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 50cd83d commit b072add

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

ref-filter.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
2626
* indexed with the "atom number", which is an index into this
2727
* array.
2828
*/
29-
static const char **used_atom;
30-
static cmp_type *used_atom_type;
29+
static struct used_atom {
30+
const char *name;
31+
cmp_type type;
32+
} *used_atom;
3133
static int used_atom_cnt, need_tagged, need_symref;
3234
static int need_color_reset_at_eol;
3335

@@ -122,8 +124,8 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
122124

123125
/* Do we have the atom already used elsewhere? */
124126
for (i = 0; i < used_atom_cnt; i++) {
125-
int len = strlen(used_atom[i]);
126-
if (len == ep - atom && !memcmp(used_atom[i], atom, len))
127+
int len = strlen(used_atom[i].name);
128+
if (len == ep - atom && !memcmp(used_atom[i].name, atom, len))
127129
return i;
128130
}
129131

@@ -150,12 +152,11 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
150152
at = used_atom_cnt;
151153
used_atom_cnt++;
152154
REALLOC_ARRAY(used_atom, used_atom_cnt);
153-
REALLOC_ARRAY(used_atom_type, used_atom_cnt);
154-
used_atom[at] = xmemdupz(atom, ep - atom);
155-
used_atom_type[at] = valid_atom[i].cmp_type;
155+
used_atom[at].name = xmemdupz(atom, ep - atom);
156+
used_atom[at].type = valid_atom[i].cmp_type;
156157
if (*atom == '*')
157158
need_tagged = 1;
158-
if (!strcmp(used_atom[at], "symref"))
159+
if (!strcmp(used_atom[at].name, "symref"))
159160
need_symref = 1;
160161
return at;
161162
}
@@ -315,7 +316,7 @@ int verify_ref_format(const char *format)
315316
at = parse_ref_filter_atom(sp + 2, ep);
316317
cp = ep + 1;
317318

318-
if (skip_prefix(used_atom[at], "color:", &color))
319+
if (skip_prefix(used_atom[at].name, "color:", &color))
319320
need_color_reset_at_eol = !!strcmp(color, "reset");
320321
}
321322
return 0;
@@ -359,7 +360,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
359360
int i;
360361

361362
for (i = 0; i < used_atom_cnt; i++) {
362-
const char *name = used_atom[i];
363+
const char *name = used_atom[i].name;
363364
struct atom_value *v = &val[i];
364365
if (!!deref != (*name == '*'))
365366
continue;
@@ -383,7 +384,7 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
383384
struct tag *tag = (struct tag *) obj;
384385

385386
for (i = 0; i < used_atom_cnt; i++) {
386-
const char *name = used_atom[i];
387+
const char *name = used_atom[i].name;
387388
struct atom_value *v = &val[i];
388389
if (!!deref != (*name == '*'))
389390
continue;
@@ -405,7 +406,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
405406
struct commit *commit = (struct commit *) obj;
406407

407408
for (i = 0; i < used_atom_cnt; i++) {
408-
const char *name = used_atom[i];
409+
const char *name = used_atom[i].name;
409410
struct atom_value *v = &val[i];
410411
if (!!deref != (*name == '*'))
411412
continue;
@@ -535,7 +536,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
535536
const char *wholine = NULL;
536537

537538
for (i = 0; i < used_atom_cnt; i++) {
538-
const char *name = used_atom[i];
539+
const char *name = used_atom[i].name;
539540
struct atom_value *v = &val[i];
540541
if (!!deref != (*name == '*'))
541542
continue;
@@ -573,7 +574,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
573574
if (!wholine)
574575
return;
575576
for (i = 0; i < used_atom_cnt; i++) {
576-
const char *name = used_atom[i];
577+
const char *name = used_atom[i].name;
577578
struct atom_value *v = &val[i];
578579
if (!!deref != (*name == '*'))
579580
continue;
@@ -663,7 +664,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
663664
unsigned long sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0;
664665

665666
for (i = 0; i < used_atom_cnt; i++) {
666-
const char *name = used_atom[i];
667+
const char *name = used_atom[i].name;
667668
struct atom_value *v = &val[i];
668669
const char *valp = NULL;
669670
if (!!deref != (*name == '*'))
@@ -809,7 +810,7 @@ static void populate_value(struct ref_array_item *ref)
809810

810811
/* Fill in specials first */
811812
for (i = 0; i < used_atom_cnt; i++) {
812-
const char *name = used_atom[i];
813+
const char *name = used_atom[i].name;
813814
struct atom_value *v = &ref->value[i];
814815
int deref = 0;
815816
const char *refname;
@@ -1464,7 +1465,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
14641465
{
14651466
struct atom_value *va, *vb;
14661467
int cmp;
1467-
cmp_type cmp_type = used_atom_type[s->atom];
1468+
cmp_type cmp_type = used_atom[s->atom].type;
14681469

14691470
get_ref_atom_value(a, s->atom, &va);
14701471
get_ref_atom_value(b, s->atom, &vb);

0 commit comments

Comments
 (0)