on master help sign in
Prevent allocation of additional Strings
9f52012sharkdp
src/bin/bat/main.rs+6−6
@@ -62,15 +62,15 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
62 Ok(())
62 Ok(())
63}
63}
64
64
65−fn get_syntax_mapping_to_paths(
65+fn get_syntax_mapping_to_paths<'a>(
66− mappings: &[(GlobMatcher, MappingTarget)],
66+ mappings: &[(GlobMatcher, MappingTarget<'a>)],
67−) -> HashMap<String, Vec<String>> {
67+) -> HashMap<&'a str, Vec<String>> {
68− let mut map: HashMap<String, Vec<String>> = HashMap::new();
68+ let mut map: HashMap<&str, Vec<String>> = HashMap::new();
69 for mapping in mappings {
69 for mapping in mappings {
70 match mapping {
70 match mapping {
71 (_, MappingTarget::MapToUnknown) => {}
71 (_, MappingTarget::MapToUnknown) => {}
72 (matcher, MappingTarget::MapTo(s)) => {
72 (matcher, MappingTarget::MapTo(s)) => {
73− let globs = map.entry((*s).into()).or_insert_with(Vec::new);
73+ let globs = map.entry(s).or_insert_with(Vec::new);
74 globs.push(matcher.glob().glob().into());
74 globs.push(matcher.glob().glob().into());
75 }
75 }
76 }
76 }
@@ -91,7 +91,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
91 let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());
91 let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());
92
92
93 for lang in languages.iter_mut() {
93 for lang in languages.iter_mut() {
94− if let Some(additional_paths) = configured_languages.get(&lang.name) {
94+ if let Some(additional_paths) = configured_languages.get(lang.name.as_str()) {
95 lang.file_extensions
95 lang.file_extensions
96 .extend(additional_paths.iter().cloned());
96 .extend(additional_paths.iter().cloned());
97 }
97 }