From 974dec38e324373bd8580c13f995932c79f96c90 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 15 Sep 2021 21:37:58 +0200 Subject: [PATCH] HighlightingAssets: Inline find_syntax_by_file_name() and find_syntax_by_file_name_extension() There is no benefit to keeping separate functions. --- src/assets.rs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 296de71c..df6943fa 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -258,9 +258,14 @@ impl HighlightingAssets { } fn get_extension_syntax(&self, file_name: &OsStr) -> Result> { - let mut syntax = self.find_syntax_by_file_name(file_name)?; + let mut syntax = self.find_syntax_by_extension(file_name.to_str().unwrap_or_default())?; if syntax.is_none() { - syntax = self.find_syntax_by_file_name_extension(file_name)?; + syntax = self.find_syntax_by_extension( + Path::new(file_name) + .extension() + .and_then(|x| x.to_str()) + .unwrap_or_default(), + )?; } if syntax.is_none() { syntax = try_with_stripped_suffix(file_name, |stripped_file_name| { @@ -270,22 +275,6 @@ impl HighlightingAssets { Ok(syntax) } - fn find_syntax_by_file_name(&self, file_name: &OsStr) -> Result> { - self.find_syntax_by_extension(file_name.to_str().unwrap_or_default()) - } - - fn find_syntax_by_file_name_extension( - &self, - file_name: &OsStr, - ) -> Result> { - self.find_syntax_by_extension( - Path::new(file_name) - .extension() - .and_then(|x| x.to_str()) - .unwrap_or_default(), - ) - } - fn get_first_line_syntax( &self, reader: &mut InputReader,