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 <olyatelezhnaya@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Olga Telezhnaya committed
Jul 17, 2018 at 08:22 UTC
a8e7e385cd239e9e862aba2038c43d4af07c187d
1 file changed
+43
-39
ref-filter.c
+43
-39
@@ -41,6 +41,7 @@ void setup_ref_filter_porcelain_msg(void)
41
42
typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
43
typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
44
+typedef enum { SOURCE_NONE = 0, SOURCE_OBJ, SOURCE_OTHER } info_source;
45
46
struct align {
47
align_type position;
@@ -73,6 +74,7 @@ struct refname_atom {
74
static struct used_atom {
75
const char *name;
76
cmp_type type;
77
+ info_source source;
78
union {
79
char color[COLOR_MAXLEN];
80
struct align align;
@@ -380,49 +382,50 @@ static int head_atom_parser(const struct ref_format *format, struct used_atom *a
382
383
static struct {
384
const char *name;
385
+ info_source source;
386
cmp_type cmp_type;
387
int (*parser)(const struct ref_format *format, struct used_atom *atom,
388
const char *arg, struct strbuf *err);
389
} 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 },
429
};
430
431
#define REF_FORMATTING_STATE_INIT { 0, NULL }
@@ -498,6 +501,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,
501
REALLOC_ARRAY(used_atom, used_atom_cnt);
502
used_atom[at].name = xmemdupz(atom, ep - atom);
503
used_atom[at].type = valid_atom[i].cmp_type;
504
+ used_atom[at].source = valid_atom[i].source;
505
if (arg) {
506
arg = used_atom[at].name + (arg - atom) + 1;
507
if (!*arg) {