From 84f31d2352094b1aa0acf8f53dc0194cbec73c51 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Tue, 25 Jul 2017 20:40:03 -0500 Subject: simplify by not creating repeat nodes if min=max=1 --- regex.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index 154a5df..02a58fa 100644 --- a/regex.c +++ b/regex.c @@ -61,21 +61,12 @@ static void print_literal(const char *s) static int get_precedence(const struct atom *a) { - const struct repeat *r; - - switch (a->type) { - case ATOM_LITERAL: + if (a->type == ATOM_LITERAL) { switch (strlen(a->u.literal)) { case 0: return -1; case 1: return precedence[ATOM_EVERYTHING]; default: return precedence[ATOM_SEQUENCE]; } - - case ATOM_REPETITION: - r = &a->u.repeat.counts; - if (r->min == 1 && r->max == 1) - return get_precedence(a->u.repeat.child); - break; } return precedence[a->type]; @@ -93,8 +84,6 @@ static void print_child_atom(const struct atom *child, const struct atom *parent static void print_atom(const struct atom *a) { - const struct repeat *r; - switch (a->type) { case ATOM_ALTERNATION: print_child_atom(a->u.children[0], a); @@ -108,13 +97,8 @@ static void print_atom(const struct atom *a) break; case ATOM_REPETITION: - r = &a->u.repeat.counts; - if (r->min == 1 && r->max == 1) { - print_atom(a->u.repeat.child); - } else { - print_child_atom(a->u.repeat.child, a); - print_repeat(r); - } + print_child_atom(a->u.repeat.child, a); + print_repeat(&a->u.repeat.counts); break; case ATOM_LITERAL: -- cgit v1.2.3