mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-28 00:18:41 +01:00
Improve iterator usage
This commit is contained in:
parent
372e42f350
commit
7956485e37
@ -351,7 +351,7 @@ impl HighlightingAssets {
|
||||
let file_path = Path::new(file_name);
|
||||
let mut syntax = None;
|
||||
if let Some(file_str) = file_path.to_str() {
|
||||
for suffix in IGNORED_SUFFIXES.iter() {
|
||||
for suffix in &IGNORED_SUFFIXES {
|
||||
if let Some(stripped_filename) = file_str.strip_suffix(suffix) {
|
||||
syntax = self.get_extension_syntax(OsStr::new(stripped_filename))?;
|
||||
break;
|
||||
|
@ -91,7 +91,7 @@ pub fn get_languages(config: &Config) -> Result<String> {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Handling of file-extension conflicts, see issue #1076
|
||||
for lang in languages.iter_mut() {
|
||||
for lang in &mut languages {
|
||||
let lang_name = lang.name.clone();
|
||||
lang.file_extensions.retain(|extension| {
|
||||
// The 'extension' variable is not certainly a real extension.
|
||||
@ -115,7 +115,7 @@ pub fn get_languages(config: &Config) -> Result<String> {
|
||||
|
||||
let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());
|
||||
|
||||
for lang in languages.iter_mut() {
|
||||
for lang in &mut languages {
|
||||
if let Some(additional_paths) = configured_languages.get(lang.name.as_str()) {
|
||||
lang.file_extensions
|
||||
.extend(additional_paths.iter().cloned());
|
||||
|
@ -175,8 +175,8 @@ impl<'b> Controller<'b> {
|
||||
let mut line_ranges: Vec<LineRange> = vec![];
|
||||
|
||||
if let Some(line_changes) = line_changes {
|
||||
for line in line_changes.keys() {
|
||||
let line = *line as usize;
|
||||
for &line in line_changes.keys() {
|
||||
let line = line as usize;
|
||||
line_ranges.push(LineRange::new(line - context, line + context));
|
||||
}
|
||||
}
|
||||
|
@ -420,8 +420,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||
let decorations = self
|
||||
.decorations
|
||||
.iter()
|
||||
.map(|d| d.generate(line_number, false, self))
|
||||
.collect::<Vec<_>>();
|
||||
.map(|d| d.generate(line_number, false, self));
|
||||
|
||||
for deco in decorations {
|
||||
write!(handle, "{} ", deco.text)?;
|
||||
@ -435,7 +434,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||
let colored_output = self.config.colored_output;
|
||||
let italics = self.config.use_italic_text;
|
||||
|
||||
for &(style, region) in regions.iter() {
|
||||
for &(style, region) in ®ions {
|
||||
let text = &*self.preprocess(region, &mut cursor_total);
|
||||
let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n');
|
||||
write!(
|
||||
@ -472,7 +471,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||
writeln!(handle)?;
|
||||
}
|
||||
} else {
|
||||
for &(style, region) in regions.iter() {
|
||||
for &(style, region) in ®ions {
|
||||
let ansi_iterator = AnsiCodeIterator::new(region);
|
||||
let mut ansi_prefix: String = String::new();
|
||||
for chunk in ansi_iterator {
|
||||
|
@ -81,7 +81,7 @@ impl<'a> SyntaxMapping<'a> {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
for glob in [
|
||||
for glob in &[
|
||||
"**/systemd/**/*.conf",
|
||||
"**/systemd/**/*.example",
|
||||
"*.automount",
|
||||
@ -100,9 +100,7 @@ impl<'a> SyntaxMapping<'a> {
|
||||
"*.swap",
|
||||
"*.target",
|
||||
"*.timer",
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
] {
|
||||
mapping.insert(glob, MappingTarget::MapTo("INI")).unwrap();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user