Skip to content

Commit

Permalink
Reserve vector capacity upfront in colors::named_color_names()
Browse files Browse the repository at this point in the history
Only because why not.
  • Loading branch information
mqudsi committed May 7, 2024
1 parent fd2ea3f commit f709795
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/color.rs
Expand Up @@ -216,10 +216,13 @@ impl RgbColor {

/// Returns the names of all named colors.
pub fn named_color_names() -> Vec<&'static wstr> {
let mut v: Vec<_> = NAMED_COLORS
.iter()
.filter_map(|&NamedColor { name, hidden, .. }| (!hidden).then_some(name))
.collect();
// We don't use all the NAMED_COLORS but we also need room for one more.
let mut v = Vec::with_capacity(NAMED_COLORS.len());
v.extend(
NAMED_COLORS
.iter()
.filter_map(|&NamedColor { name, hidden, .. }| (!hidden).then_some(name)),
);

// "normal" isn't really a color and does not have a color palette index or
// RGB value. Therefore, it does not appear in the NAMED_COLORS table.
Expand Down

0 comments on commit f709795

Please sign in to comment.