Cache Regex's
This commit is contained in:
parent
2b6371dbfb
commit
5f1da8e533
3 changed files with 16 additions and 3 deletions
|
@ -3801,6 +3801,7 @@ dependencies = [
|
||||||
name = "tidy"
|
name = "tidy"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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)",
|
"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 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)",
|
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -8,3 +8,4 @@ edition = "2018"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
serde = { version = "1.0.8", features = ["derive"] }
|
serde = { version = "1.0.8", features = ["derive"] }
|
||||||
serde_json = "1.0.2"
|
serde_json = "1.0.2"
|
||||||
|
lazy_static = "1"
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::fs::{self, File};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use regex::{Regex, escape};
|
use regex::Regex;
|
||||||
|
|
||||||
mod version;
|
mod version;
|
||||||
use version::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> {
|
fn find_attr_val<'a>(line: &'a str, attr: &str) -> Option<&'a str> {
|
||||||
let r = Regex::new(&format!(r#"{}\s*=\s*"([^"]*)""#, escape(attr)))
|
lazy_static::lazy_static! {
|
||||||
.expect("malformed regex for find_attr_val");
|
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)
|
r.captures(line)
|
||||||
.and_then(|c| c.get(1))
|
.and_then(|c| c.get(1))
|
||||||
.map(|m| m.as_str())
|
.map(|m| m.as_str())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue