]> git.lizzy.rs Git - rust.git/commitdiff
Cache Regex's
authorMark Rousskov <mark.simulacrum@gmail.com>
Fri, 21 Jun 2019 16:04:27 +0000 (12:04 -0400)
committerMark Rousskov <mark.simulacrum@gmail.com>
Sun, 23 Jun 2019 13:10:08 +0000 (09:10 -0400)
Cargo.lock
src/tools/tidy/Cargo.toml
src/tools/tidy/src/features.rs

index 40b8cf507e97c5b95ec70ca58237359ead967f37..a9f9cd2b97783cfbd9d3065e37a66fe2506905e3 100644 (file)
@@ -3801,6 +3801,7 @@ dependencies = [
 name = "tidy"
 version = "0.1.0"
 dependencies = [
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
index eeac6cfbb30e0cda50192c8d915a51e722347403..fb58adcf9b282e2d6a5996a39f43bb493d74e21a 100644 (file)
@@ -8,3 +8,4 @@ edition = "2018"
 regex = "1"
 serde = { version = "1.0.8", features = ["derive"] }
 serde_json = "1.0.2"
+lazy_static = "1"
index 6aa093c1ef0d1c5be951fb2bb6fea50cb543e1dc..ced30eb6d58ad3ea5c1ad5c17afa905054be0a5b 100644 (file)
@@ -15,7 +15,7 @@
 use std::io::prelude::*;
 use std::path::Path;
 
-use regex::{Regex, escape};
+use regex::Regex;
 
 mod version;
 use version::Version;
@@ -159,8 +159,19 @@ fn format_features<'a>(features: &'a Features, family: &'a str) -> impl Iterator
 }
 
 fn find_attr_val<'a>(line: &'a str, attr: &str) -> Option<&'a str> {
-    let r = Regex::new(&format!(r#"{}\s*=\s*"([^"]*)""#, escape(attr)))
-        .expect("malformed regex for find_attr_val");
+    lazy_static::lazy_static! {
+        static ref ISSUE: Regex = Regex::new(r#"issue\s*=\s*"([^"]*)""#).unwrap();
+        static ref FEATURE: Regex = Regex::new(r#"feature\s*=\s*"([^"]*)""#).unwrap();
+        static ref SINCE: Regex = Regex::new(r#"since\s*=\s*"([^"]*)""#).unwrap();
+    }
+
+    let r = match attr {
+        "issue" => &*ISSUE,
+        "feature" => &*FEATURE,
+        "since" => &*SINCE,
+        _ => unimplemented!("{} not handled", attr),
+    };
+
     r.captures(line)
         .and_then(|c| c.get(1))
         .map(|m| m.as_str())