Skip to content

Commit 95022cb

Browse files
telezhnayagitster
authored andcommitted
ref-filter: add info_source to valid_atom
Add the source of object data to prevent parsing of unneeded data. The goal is to improve performance by avoiding calling expensive functions when we don't need the information they provide or when we could get it by using a cheaper function. It is stored in valid_atoms because it depends on the atoms we are interested in. Signed-off-by: Olga Telezhnaia <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e333175 commit 95022cb

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

ref-filter.c

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void setup_ref_filter_porcelain_msg(void)
4141

4242
typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
4343
typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
44+
typedef enum { SOURCE_NONE = 0, SOURCE_OBJ, SOURCE_OTHER } info_source;
4445

4546
struct align {
4647
align_type position;
@@ -73,6 +74,7 @@ struct refname_atom {
7374
static struct used_atom {
7475
const char *name;
7576
cmp_type type;
77+
info_source source;
7678
union {
7779
char color[COLOR_MAXLEN];
7880
struct align align;
@@ -380,49 +382,50 @@ static int head_atom_parser(const struct ref_format *format, struct used_atom *a
380382

381383
static struct {
382384
const char *name;
385+
info_source source;
383386
cmp_type cmp_type;
384387
int (*parser)(const struct ref_format *format, struct used_atom *atom,
385388
const char *arg, struct strbuf *err);
386389
} valid_atom[] = {
387-
{ "refname" , FIELD_STR, refname_atom_parser },
388-
{ "objecttype" },
389-
{ "objectsize", FIELD_ULONG },
390-
{ "objectname", FIELD_STR, objectname_atom_parser },
391-
{ "tree" },
392-
{ "parent" },
393-
{ "numparent", FIELD_ULONG },
394-
{ "object" },
395-
{ "type" },
396-
{ "tag" },
397-
{ "author" },
398-
{ "authorname" },
399-
{ "authoremail" },
400-
{ "authordate", FIELD_TIME },
401-
{ "committer" },
402-
{ "committername" },
403-
{ "committeremail" },
404-
{ "committerdate", FIELD_TIME },
405-
{ "tagger" },
406-
{ "taggername" },
407-
{ "taggeremail" },
408-
{ "taggerdate", FIELD_TIME },
409-
{ "creator" },
410-
{ "creatordate", FIELD_TIME },
411-
{ "subject", FIELD_STR, subject_atom_parser },
412-
{ "body", FIELD_STR, body_atom_parser },
413-
{ "trailers", FIELD_STR, trailers_atom_parser },
414-
{ "contents", FIELD_STR, contents_atom_parser },
415-
{ "upstream", FIELD_STR, remote_ref_atom_parser },
416-
{ "push", FIELD_STR, remote_ref_atom_parser },
417-
{ "symref", FIELD_STR, refname_atom_parser },
418-
{ "flag" },
419-
{ "HEAD", FIELD_STR, head_atom_parser },
420-
{ "color", FIELD_STR, color_atom_parser },
421-
{ "align", FIELD_STR, align_atom_parser },
422-
{ "end" },
423-
{ "if", FIELD_STR, if_atom_parser },
424-
{ "then" },
425-
{ "else" },
390+
{ "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
391+
{ "objecttype", SOURCE_OTHER },
392+
{ "objectsize", SOURCE_OTHER, FIELD_ULONG },
393+
{ "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser },
394+
{ "tree", SOURCE_OBJ },
395+
{ "parent", SOURCE_OBJ },
396+
{ "numparent", SOURCE_OBJ, FIELD_ULONG },
397+
{ "object", SOURCE_OBJ },
398+
{ "type", SOURCE_OBJ },
399+
{ "tag", SOURCE_OBJ },
400+
{ "author", SOURCE_OBJ },
401+
{ "authorname", SOURCE_OBJ },
402+
{ "authoremail", SOURCE_OBJ },
403+
{ "authordate", SOURCE_OBJ, FIELD_TIME },
404+
{ "committer", SOURCE_OBJ },
405+
{ "committername", SOURCE_OBJ },
406+
{ "committeremail", SOURCE_OBJ },
407+
{ "committerdate", SOURCE_OBJ, FIELD_TIME },
408+
{ "tagger", SOURCE_OBJ },
409+
{ "taggername", SOURCE_OBJ },
410+
{ "taggeremail", SOURCE_OBJ },
411+
{ "taggerdate", SOURCE_OBJ, FIELD_TIME },
412+
{ "creator", SOURCE_OBJ },
413+
{ "creatordate", SOURCE_OBJ, FIELD_TIME },
414+
{ "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
415+
{ "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
416+
{ "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
417+
{ "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
418+
{ "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
419+
{ "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
420+
{ "symref", SOURCE_NONE, FIELD_STR, refname_atom_parser },
421+
{ "flag", SOURCE_NONE },
422+
{ "HEAD", SOURCE_NONE, FIELD_STR, head_atom_parser },
423+
{ "color", SOURCE_NONE, FIELD_STR, color_atom_parser },
424+
{ "align", SOURCE_NONE, FIELD_STR, align_atom_parser },
425+
{ "end", SOURCE_NONE },
426+
{ "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
427+
{ "then", SOURCE_NONE },
428+
{ "else", SOURCE_NONE },
426429
};
427430

428431
#define REF_FORMATTING_STATE_INIT { 0, NULL }
@@ -498,6 +501,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,
498501
REALLOC_ARRAY(used_atom, used_atom_cnt);
499502
used_atom[at].name = xmemdupz(atom, ep - atom);
500503
used_atom[at].type = valid_atom[i].cmp_type;
504+
used_atom[at].source = valid_atom[i].source;
501505
if (arg) {
502506
arg = used_atom[at].name + (arg - atom) + 1;
503507
if (!*arg) {

0 commit comments

Comments
 (0)