Skip to content

Commit

Permalink
Handle common case first and minor efficiency tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Nov 23, 2020
1 parent 68498c4 commit 54f363d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..] {
Expand All @@ -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()
Expand Down

0 comments on commit 54f363d

Please sign in to comment.