summaryrefslogtreecommitdiff
path: root/regex.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-07-25 20:40:03 -0500
committerBobby Bingham <koorogi@koorogi.info>2017-07-25 20:40:03 -0500
commit84f31d2352094b1aa0acf8f53dc0194cbec73c51 (patch)
treed40ebba29830e9ec2a9842632ce3a80f35f535ad /regex.c
parent4459545e6528c8f072de79b799b9ae9b85d01dfb (diff)
simplify by not creating repeat nodes if min=max=1
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c22
1 files changed, 3 insertions, 19 deletions
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: