From 157c8359224a506c5be0012f3c01a54c391989e4 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 2 Jun 2022 01:18:37 -0400 Subject: [PATCH] force size of FunctionManager --- src/function_manager.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/function_manager.rs b/src/function_manager.rs index 681ba19..4e1c624 100644 --- a/src/function_manager.rs +++ b/src/function_manager.rs @@ -1,3 +1,4 @@ +use crate::consts::COLORS; use crate::function_entry::FunctionEntry; use crate::misc::random_u64; use crate::widgets::widgets_ontop; @@ -14,18 +15,19 @@ use std::hash::Hash; use std::hash::Hasher; use std::ops::BitXorAssign; +type Functions = Vec<(Id, FunctionEntry)>; pub struct FunctionManager { - functions: Vec<(Id, FunctionEntry)>, + functions: Functions, } impl Default for FunctionManager { fn default() -> Self { - Self { - functions: vec![( - Id::new_from_u64(11414819524356497634), // Random number here to avoid call to crate::misc::random_u64() - FunctionEntry::EMPTY, - )], - } + let mut vec: Functions = Vec::with_capacity(COLORS.len()); + vec.push(( + Id::new_from_u64(11414819524356497634), // Random number here to avoid call to crate::misc::random_u64() + FunctionEntry::EMPTY, + )); + Self { functions: vec } } } @@ -264,8 +266,8 @@ impl FunctionManager { pub fn len(&self) -> usize { self.functions.len() } #[inline] - pub fn get_entries_mut(&mut self) -> &mut Vec<(Id, FunctionEntry)> { &mut self.functions } + pub fn get_entries_mut(&mut self) -> &mut Functions { &mut self.functions } #[inline] - pub fn get_entries(&self) -> &Vec<(Id, FunctionEntry)> { &self.functions } + pub fn get_entries(&self) -> &Functions { &self.functions } }