Skip to content

Commit

Permalink
Reduce allocations during --show-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelc committed Feb 5, 2023
1 parent ce6448f commit 21de00c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
20 changes: 5 additions & 15 deletions src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::iter::FromIterator;

pub fn color_groups() -> HashMap<String, Vec<(String, String)>> {
[
pub fn color_groups() -> BTreeMap<&'static str, Vec<(&'static str, &'static str)>> {
BTreeMap::from_iter([
(
"Blue",
vec![
Expand Down Expand Up @@ -198,16 +199,5 @@ pub fn color_groups() -> HashMap<String, Vec<(String, String)>> {
("darkkhaki", "#bdb76b"),
],
),
]
.iter()
.map(|(name, colors)| {
(
name.to_string(),
colors
.iter()
.map(|(color, hex)| (color.to_string(), hex.to_string()))
.collect(),
)
})
.collect()
])
}
4 changes: 1 addition & 3 deletions src/subcommands/show_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 21de00c

Please sign in to comment.