Perf: prefer non-allocating, case-insensitive string comparisons (#905)

This commit is contained in:
Basti Ortiz 2022-08-14 23:35:13 +08:00 committed by GitHub
parent 5021a6d324
commit 955d258692
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,13 +21,18 @@ impl FromStr for Sort {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s.to_lowercase().as_ref() {
"blanks" => Sort::Blanks,
"comments" => Sort::Comments,
"code" => Sort::Code,
"files" => Sort::Files,
"lines" => Sort::Lines,
s => return Err(format!("Unsupported sorting option: {}", s)),
Ok(if s.eq_ignore_ascii_case("blanks") {
Sort::Blanks
} else if s.eq_ignore_ascii_case("comments") {
Sort::Comments
} else if s.eq_ignore_ascii_case("code") {
Sort::Code
} else if s.eq_ignore_ascii_case("files") {
Sort::Files
} else if s.eq_ignore_ascii_case("lines") {
Sort::Lines
} else {
return Err(format!("Unsupported sorting option: {}", s));
})
}
}