mirror of https://github.com/rust-lang/rust.git
Cache Regex's
This commit is contained in:
parent
2b6371dbfb
commit
5f1da8e533
|
@ -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)",
|
||||
|
|
|
@ -8,3 +8,4 @@ edition = "2018"
|
|||
regex = "1"
|
||||
serde = { version = "1.0.8", features = ["derive"] }
|
||||
serde_json = "1.0.2"
|
||||
lazy_static = "1"
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::fs::{self, File};
|
|||
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())
|
||||
|
|
Loading…
Reference in New Issue