diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-11-22 19:02:59 -0500 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-11-22 19:08:57 -0500 |
commit | 54f363db05f91dc83737bb45244ec00f0c2bbcf3 (patch) | |
tree | 8c8849f65c5938711dfaebfc2009138936723fd1 | |
parent | 68498c455abe710a6dd9c970403a1b5c3a5515cf (diff) |
Handle common case first and minor efficiency tweak
-rw-r--r-- | src/parse.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/parse.rs b/src/parse.rs index 6188117d..9be8df51 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -21,14 +21,6 @@ pub fn get_file_extension_from_marker_line(line: &str) -> Option<&str> { pub fn get_file_path_from_file_meta_line(line: &str, git_diff_name: bool) -> String { match line { - line if line.starts_with("rename from ") => { - let offset = "rename from ".len(); - &line[offset..] - } - line if line.starts_with("rename to ") => { - let offset = "rename to ".len(); - &line[offset..] - } line if line.starts_with("--- ") || line.starts_with("+++ ") => { let offset = 4; match &line[offset..] { @@ -40,6 +32,12 @@ pub fn get_file_path_from_file_meta_line(line: &str, git_diff_name: bool) -> Str path => path.split('\t').next().unwrap_or(""), } } + line if line.starts_with("rename from ") => { + &line[12..] // "rename from ".len() + } + line if line.starts_with("rename to ") => { + &line[10..] // "rename to ".len() + } _ => "", } .to_string() |