From f4be222c4485a0f4a87b119c1054c528a99208e6 Mon Sep 17 00:00:00 2001 From: nickelc Date: Tue, 28 Feb 2023 12:49:28 +0100 Subject: Reduce allocations during `--show-colors` (#1315) The colors are already sorted and can be returned as they are defined. --- src/colors.rs | 17 ++--------------- src/subcommands/show_colors.rs | 4 +--- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/colors.rs b/src/colors.rs index 00e826a1..5c9d5c94 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -1,7 +1,5 @@ -use std::collections::HashMap; - -pub fn color_groups() -> HashMap> { - [ +pub fn color_groups() -> Vec<(&'static str, Vec<(&'static str, &'static str)>)> { + vec![ ( "Blue", vec![ @@ -199,15 +197,4 @@ pub fn color_groups() -> HashMap> { ], ), ] - .iter() - .map(|(name, colors)| { - ( - name.to_string(), - colors - .iter() - .map(|(color, hex)| (color.to_string(), hex.to_string())) - .collect(), - ) - }) - .collect() } diff --git a/src/subcommands/show_colors.rs b/src/subcommands/show_colors.rs index d7829372..4ad19589 100644 --- a/src/subcommands/show_colors.rs +++ b/src/subcommands/show_colors.rs @@ -12,8 +12,6 @@ use crate::utils::bat::output::{OutputType, PagingMode}; #[cfg(not(tarpaulin_include))] pub fn show_colors() -> std::io::Result<()> { - use itertools::Itertools; - use crate::{delta::DiffType, utils}; let assets = utils::bat::assets::load_highlighting_assets(); @@ -38,7 +36,7 @@ pub fn show_colors() -> std::io::Result<()> { is_syntax_highlighted: true, ..style::Style::default() }; - for (group, color_names) in colors::color_groups().iter().sorted() { + for (group, color_names) in colors::color_groups() { writeln!(painter.writer, "\n\n{}\n", title_style.paint(group))?; for (color_name, hex) in color_names { // Two syntax-highlighted lines without background color -- cgit v1.2.3