diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-01-07 21:46:22 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-01-07 21:46:24 -0800 |
commit | f2c1f1c13772145acaecb1ebf9b4cafcacb98131 (patch) | |
tree | 8def62d9d0f2beb1d42a87ff3af07e49330f7c10 /modelica-parser-lalrpop/src | |
parent | f606f6acb36e028e66fa4225ed7d46d2bd653f6f (diff) | |
download | modelthing-f2c1f1c13772145acaecb1ebf9b4cafcacb98131.tar.gz modelthing-f2c1f1c13772145acaecb1ebf9b4cafcacb98131.zip |
parser: statically compile regex w/ lazy_static
As per regex library's documentation
Diffstat (limited to 'modelica-parser-lalrpop/src')
-rw-r--r-- | modelica-parser-lalrpop/src/lib.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/modelica-parser-lalrpop/src/lib.rs b/modelica-parser-lalrpop/src/lib.rs index b515d73..ed07ca2 100644 --- a/modelica-parser-lalrpop/src/lib.rs +++ b/modelica-parser-lalrpop/src/lib.rs @@ -2,6 +2,7 @@ extern crate lalrpop_util; extern crate colored; extern crate regex; +#[macro_use] extern crate lazy_static; mod parser; mod ast; @@ -20,12 +21,12 @@ pub use parser::{ }; pub fn strip_comments(raw: &str) -> String { - // TODO: shouldn't recompile regex on every function call - // Match on comments: // (?m) sets multi-line mode - let comment_re = Regex::new(r"(?m)(//.*)$").unwrap(); - comment_re.replace_all(&raw, "") + lazy_static! { + static ref RE: Regex = Regex::new(r"(?m)(//.*)$").unwrap(); + } + RE.replace_all(&raw, "") } fn pp_segment(raw: &str, start: usize, end: usize) -> String { |