Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5f1da8e

Browse files
Cache Regex's
1 parent 2b6371d commit 5f1da8e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,7 @@ dependencies = [
38013801
name = "tidy"
38023802
version = "0.1.0"
38033803
dependencies = [
3804+
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
38043805
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
38053806
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
38063807
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ edition = "2018"
88
regex = "1"
99
serde = { version = "1.0.8", features = ["derive"] }
1010
serde_json = "1.0.2"
11+
lazy_static = "1"

src/tools/tidy/src/features.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::fs::{self, File};
1515
use std::io::prelude::*;
1616
use std::path::Path;
1717

18-
use regex::{Regex, escape};
18+
use regex::Regex;
1919

2020
mod version;
2121
use version::Version;
@@ -159,8 +159,19 @@ fn format_features<'a>(features: &'a Features, family: &'a str) -> impl Iterator
159159
}
160160

161161
fn find_attr_val<'a>(line: &'a str, attr: &str) -> Option<&'a str> {
162-
let r = Regex::new(&format!(r#"{}\s*=\s*"([^"]*)""#, escape(attr)))
163-
.expect("malformed regex for find_attr_val");
162+
lazy_static::lazy_static! {
163+
static ref ISSUE: Regex = Regex::new(r#"issue\s*=\s*"([^"]*)""#).unwrap();
164+
static ref FEATURE: Regex = Regex::new(r#"feature\s*=\s*"([^"]*)""#).unwrap();
165+
static ref SINCE: Regex = Regex::new(r#"since\s*=\s*"([^"]*)""#).unwrap();
166+
}
167+
168+
let r = match attr {
169+
"issue" => &*ISSUE,
170+
"feature" => &*FEATURE,
171+
"since" => &*SINCE,
172+
_ => unimplemented!("{} not handled", attr),
173+
};
174+
164175
r.captures(line)
165176
.and_then(|c| c.get(1))
166177
.map(|m| m.as_str())

0 commit comments

Comments
 (0)