summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornickelc <constantin.nickel@gmail.com>2023-02-28 12:49:28 +0100
committerGitHub <noreply@github.com>2023-02-28 06:49:28 -0500
commitf4be222c4485a0f4a87b119c1054c528a99208e6 (patch)
treeed5691efdeea16184c53576b8a555351594bd34c
parent17ad30e514b8f98982c36389c099a0417b0e8063 (diff)
Reduce allocations during `--show-colors` (#1315)
The colors are already sorted and can be returned as they are defined.
-rw-r--r--src/colors.rs17
-rw-r--r--src/subcommands/show_colors.rs4
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<String, Vec<(String, String)>> {
- [
+pub fn color_groups() -> Vec<(&'static str, Vec<(&'static str, &'static str)>)> {
+ vec![
(
"Blue",
vec![
@@ -199,15 +197,4 @@ pub fn color_groups() -> HashMap<String, Vec<(String, String)>> {
],
),
]
- .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