From f709795a3aa30405d04aa517f66e2ce93c3b5547 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 7 May 2024 13:09:40 -0500 Subject: [PATCH] Reserve vector capacity upfront in colors::named_color_names() Only because why not. --- src/color.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/color.rs b/src/color.rs index d9f1e6f69..f328185a1 100644 --- a/src/color.rs +++ b/src/color.rs @@ -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.