changeset 65:094c91f3213f

Automatically optimize patterns before compiling
author Lewin Bormann <lbo@spheniscida.de>
date Fri, 30 Aug 2019 22:59:37 +0200
parents 4d2feb7c37f7
children ae022a4c1234
files src/lib.rs
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib.rs	Fri Aug 30 22:52:09 2019 +0200
+++ b/src/lib.rs	Fri Aug 30 22:59:37 2019 +0200
@@ -9,6 +9,7 @@
 
 mod tests;
 
+pub use state::dot as debug_graph_to_dot;
 
 fn parse(re: &str) -> Result<repr::Pattern, String> {
     return parse::parse(re);
@@ -27,13 +28,13 @@
 /// regular expression will be compiled every time. Use `compile()` and `match_re()` to make this
 /// more efficient (about 3x faster).
 pub fn match_re_str(re: &str, s: &str) -> Result<(bool, Vec<(usize, usize)>), String> {
-    return Ok(compile_and_match(&parse::parse(re)?, s));
+    return Ok(compile_and_match(&repr::optimize::optimize(parse::parse(re)?), s));
 }
 
 /// Compile a regular expression into a representation that can be directly used for matching with
 /// `match_re()`.
 pub fn compile(re: &str) -> Result<state::CompiledRE, String> {
-    Ok(compile::start_compile(&parse(re)?))
+    Ok(compile::start_compile(&repr::optimize::optimize(parse(re)?)))
 }
 
 /// Match a regular expression compiled with `compile()` against a string. Returns a tuple of a