aboutsummaryrefslogtreecommitdiff
path: root/builtins/text.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-07 02:51:14 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-07 02:51:14 -0400
commitcbf0bc9207b71e67d43f73b6e6474fd839ce3fbd (patch)
tree63d8bd13c8aca97c46e4de3421b706d95d9211e4 /builtins/text.c
parent5927ba86e342201f0f4feda90dc6836b7fd52176 (diff)
Optimization to terminate pattern searches early if there's a greedy
{..} at the end
Diffstat (limited to 'builtins/text.c')
-rw-r--r--builtins/text.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/builtins/text.c b/builtins/text.c
index f322deb3..fb71d8d0 100644
--- a/builtins/text.c
+++ b/builtins/text.c
@@ -1630,6 +1630,11 @@ int64_t match(Text_t text, int64_t text_index, Pattern_t pattern, int64_t patter
}
}
+ if (pat.tag == PAT_ANY && !pat.negated && pattern_index >= pattern.length) {
+ int64_t remaining = text.length - text_index;
+ return remaining >= pat.min ? MIN(remaining, pat.max) : -1;
+ }
+
int64_t capture_start = text_index;
int64_t count = 0, capture_len = 0, next_match_len = 0;