summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-07-17 19:50:29 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-07-17 19:50:29 +0200
commit12868c33be2d16d504869871b607793201ec3257 (patch)
treea7e66de4810b17cb9219cee64005e990f0678dc5 /src
parent6c2a2d7f0b65ab0bf7da35b871697abde5b075e1 (diff)
Use lazy_static to not recompile regex every timeHEADmaster
This introduces lazy_static as a new dependency so that the regex does not have to be compiled every time the function is called. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/git.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/git.rs b/src/git.rs
index daaceb0..68afd52 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -32,13 +32,15 @@ pub fn crawl_git_tree<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
}
pub fn parse_ls_tree_output<'a>(output: &'a [u8]) -> Result<Vec<Blob<'a>>, Utf8Error> {
- let re = Regex::new(r"^[^ ]+ [^ ]+ ([^\t]+)\t(.+)$").unwrap();
+ lazy_static::lazy_static! {
+ static ref RE: Regex = Regex::new(r"^[^ ]+ [^ ]+ ([^\t]+)\t(.+)$").unwrap();
+ }
output.split(|byte| *byte == 0)
.map(str::from_utf8)
.filter_map(|r_l| match r_l {
Err(e) => Some(Err(e)),
- Ok(l) => re.captures(l).map(Ok),
+ Ok(l) => RE.captures(l).map(Ok),
})
.map(|r_captures| r_captures.map(|captures| Blob {
object: captures.get(1).unwrap().as_str(),