use lazy_static so we do not compile regex multiple times

This commit is contained in:
Matthias Beyer 2016-02-20 21:06:47 +01:00
parent 0bf22672f9
commit df4bc13018
3 changed files with 11 additions and 7 deletions

View file

@ -6,6 +6,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies]
fs2 = "0.2.2"
glob = "0.2.10"
lazy_static = "0.1.15"
log = "0.3.5"
regex = "0.1.47"
semver = "0.2"

View file

@ -2,6 +2,7 @@
#[macro_use] extern crate version;
extern crate fs2;
extern crate glob;
#[macro_use] extern crate lazy_static;
extern crate regex;
extern crate toml;
#[cfg(test)] extern crate tempdir;

View file

@ -870,14 +870,16 @@ impl Entry {
pub fn from_str(loc: StoreId, s: &str) -> Result<Entry> {
debug!("Building entry from string");
let re = Regex::new(r"(?smx)
^---$
(?P<header>.*) # Header
^---$\n
(?P<content>.*) # Content
").unwrap();
lazy_static! {
static ref RE: Regex = Regex::new(r"(?smx)
^---$
(?P<header>.*) # Header
^---$\n
(?P<content>.*) # Content
").unwrap();
}
let matches = re.captures(s);
let matches = RE.captures(s);
if matches.is_none() {
return Err(StoreError::new(StoreErrorKind::MalformedEntry, None));